I have a dataset in pandas with column pid (patient id), and code (drug code), sorted in rows as the example shows. I need to convert them to 1 patient/row, and list all the drugs as attributes for each patient.
What I have now:
pid code
1 Az
1 Bn
2 Az
2 Bn
2 C4
3 Bn
3 C4
3 Dx
4 Az
4 Bn
4 Dx
4 E
5 C4
5 Dx
5 E
I need to convert it to:
pid Az Bn C4 Dx E
1 y y n n n
2 y y y n n
3 n y y y n
4 y y n y y
5 n n y y y