I have medical data split into two different CSVs, and I need to merge them. One data set contains basic demographic information, and the second contains diagnosis codes. Each patient is assigned a unique identification number called INC_KEY, which I've simplified to simple numbers, as shown in this example:
df1:
INC_KEY SEX AGE
1 F 40
2 F 24
3 M 66
df2:
INC_KEY DCODE
1 BW241ZZ
1 BW28ZZZ
2 0BH17EZ
3 05H633Z
2 4A103BD
3 BR30ZZZ
1 BF42ZZZ
I need to merge the two dataframes with the output containing the three rows as seen in df1 with appended columns for each dcode respective to that patient. Like this:
INC_KEY SEX AGE DCODE1 DCODE2 DCODE3
1 F 40 BW241ZZ BW28ZZZ BF42ZZZ
2 F 24 0BH17EZ 4A103BD N/A
3 M 66 05H633Z BR30ZZZ N/A
How can I go about this? I've tried to do a left merge but it does not give the result I am looking for.