Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 1967
Alex Hales
  • 0
Alex HalesTeacher
Asked: May 31, 20222022-05-31T09:21:06+00:00 2022-05-31T09:21:06+00:00

python – Compare two CSVs and find closest centroid match

  • 0

[ad_1]

I have two CSV files, which contain an index, X, Y, and value. It looks something like this.

CSV1 CSV2

X and Y coordinates are not an exact match, but only a close match. The index is assigned randomly. The total no. of rows can be more or less.
Now, I want to match centroids and subtract values at the corresponding centroid to get an idea of the difference.

My main hindrance is to match centroids. Once centroids are matched between CSV1 and CSV2, I might be able to map indices and get values.

Expected output: output I am mainly concerned about this value_diff.

I am using pandas to read CSV as:

file1 = pd.read_csv('CSV1')
file2 = pd.read_csv('CSV2')

I figured to map centroid I can use a Euclidean distance match. And thus created a function for calculating it:

def dist(x0, x1, y0, y1):
    return ((x1 - x0)**2 + (y1 - y0)**2)**(1/2)

After this, I am not sure how to proceed. I got a function to find the nearest value in the array using this answer and now I am trying to expand it to more than one row:

def find_nearest(array, value):
    array = np.asarray(array)
    idx = (np.abs(array - value)).argmin()
    return idx,array[idx]

[ad_2]

  • 0 0 Answers
  • 9 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 5256 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1098 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1047 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.