0

i have two dataframes, which are interrelated. I want to merge them, but i could not.

First Dataframe

Second Dataframe

I want to merge all rows with the same value as "PatientID_Time" and "PatientID_Time" columns and create a new df.

My goal is to find the equivalent SeqID and HB_Mayo_impu values.

Naveed
  • 11,495
  • 2
  • 14
  • 21

1 Answers1

1

IIUC, if patient_id is a common column among the two DF, then df.merge should be the answer.

If you post the Data as code, it'll be simpler to reproduce and share the result

df.merge(df1, how='left', on='PatientID_Time')
Naveed
  • 11,495
  • 2
  • 14
  • 21
  • 1
    For such simple `merge` questions, better close with a link to [`merge 101`](https://stackoverflow.com/questions/53645882/pandas-merging-101) – mozway Aug 23 '22 at 18:14
  • hey thanks for replying! actually patient_id is not common column. The dimensions of dfs are different. There are common values but all of them are not common. I want to get some NaN values and than drop them. – RECEP TAYYİP DURGUT Aug 23 '22 at 18:17
  • @RECEPTAYYİPDURGUT, refer to the merge link mozway has copied in his comment. The merge will result in all rows from DF, and only take the matching ones from the other ones, else NaN. Try it out – Naveed Aug 23 '22 at 18:20