python - Pandas: Pivoting on column of lists? -


i have dataframe in pandas:

                      age interventiontype primarypurpose 0         [adult, senior]           device    treatment 1  [child, adult, senior]             drug    basic science 2         [adult, senior]             drug    treatment 3         [adult, senior]              nan            nan 4         [adult, senior]            other            nan 

and want to pivot on interventiontype, such get:

drug     adult     2          senior    2          child     1 device   adult     1          senior    1 other    adult     1          senior    1 

how accomplish this? also, non-standard dataframe have lists? if so, practice "de-list" lists?


Comments