0

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()]

enter image description here

I want it to look like this:

enter image description here

but since 'variable' changes, the aggregation is going to be wrong.

meds_final = meds.groupby(['Vendor', 'patientid', 'Medication']).count()

enter image description here

CreepyRaccoon
  • 826
  • 1
  • 9
  • 19
BP12
  • 27
  • 6

1 Answers1

0

turns out after I split the column I forgot to strip it, so 'Drug A' was ' Drug A' or ' Drug A', hence the groupby wasn't doing what I was hoping :-)

BP12
  • 27
  • 6