-1

I would like to merge pandas data frame records to one single record.

Given a dataframe like this:

patient_id  gender  age admission_id    admission_type  insurance_type  language    religion    marital_status  ethnicity   diagnosis   icustay_id  length_of_stay  BUN Creatinine  Hematocrit  Non Invasive Blood Pressure diastolic   Non Invasive Blood Pressure systolic
0   2365    F   51  117027  1   2   ENGL    CATHOLIC    SINGLE  WHITE   GASTROINTESTINAL BLEED  250042  22.9776 NaN 2.1 NaN NaN NaN
1   2365    F   51  117027  1   2   ENGL    CATHOLIC    SINGLE  WHITE   GASTROINTESTINAL BLEED  250042  22.9776 44.0    NaN NaN NaN NaN

Expected output:

patient_id  gender  age admission_id    admission_type  insurance_type  language    religion    marital_status  ethnicity   diagnosis   icustay_id  length_of_stay  BUN Creatinine  Hematocrit  Non Invasive Blood Pressure diastolic   Non Invasive Blood Pressure systolic
0   2365    F   51  117027  1   2   ENGL    CATHOLIC    SINGLE  WHITE   GASTROINTESTINAL BLEED  250042  22.9776 44 2.1 NaN NaN NaN
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45
Bharath_Raja
  • 622
  • 8
  • 16

1 Answers1

1

You can do groupby with first ,notice here I assume the patient_id is the groupby key

out = df.groupby('patient_id').first()
BENY
  • 317,841
  • 20
  • 164
  • 234