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

Match two datasets on two columns in python (date being one of these values)

I have a two datasets where I would like to match on the date and a specific column.

Data

df1

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

label   date        type1   stat1
111     7/1/2021    y      n
222     8/1/2021    y      n
333     9/1/2021    n      y

df2

  id   date_1      type   stat
  111  7/1/2021    y      n
  222  7/20/2021   y      n
  333  7/30/2021   n      y

Desired

id   date        type   stat   date_1      label     type1   stat1
111  7/1/2021    y      n      7/1/2021    111       y       n
222  8/1/2021    y      n
333  9/1/2021    n      y

Doing

I figure I can treat as a string and do a left join. How would I join on
date value as well as the type column?
Any insight is appreciated.

df4 = df1.merge(df2, how='inner', left_on=["date","type1"], right_on=["date_1", "type"])

Although the dates are true dates

>Solution :

then it should be like this :

df3 = df1.merge(server, left_on=['date','type1'], right_on=['date_1','type'], how='left')
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