I have a vendor supplied file that stores n
medications in a single column separated by ;
. I'm struggling trying to melt
, then groupby
the dateframe.
meds = meds.melt(id_vars=['Vendor', 'patientid'], value_name='Medication')
meds = meds.loc[meds['Medication'].notnull()]
I want it to look like this:
but since 'variable' changes, the aggregation is going to be wrong.
meds_final = meds.groupby(['Vendor', 'patientid', 'Medication']).count()