Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: merging two datasets via df.merge() is simply not working

I simply want to merg two datasets.

Sample df1:

ID Name
0 73 Dan
1 74 Emily
2 75 Kenny
333333 333407 Liz

Sample df2:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Intention Product ID
0 buy 1001
1 sell 1002
2 buy 1002
333333 buy 1011

I want the result to look like this:

ID Name Intention Product
0 73 Dan buy 1001
1 74 Emily sell 1002
2 75 Kenny buy 1002
333333 333407 Liz buy 1011

I always used to do it this way and it always worked:

df1.merge(df2, left_on=df1.index, right_on=df2.merge)

But now I am getting an error:
ValueError: Unable to fill values because RangeIndex cannot contain NA

These datasets have the same number of rows, so the indexes. Cannot understand what’s wrong. What do you think?

>Solution :

You can try pd.concat

df = pd.concat([df1, df2], axis=1)

Or with

df = df1.merge(df2, left_index=True, right_index=True)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading