I have data with 4 columns . I want to perform group by with melt.
data:
col1 col2 col3 col4
de1 do1 2020-11-24 vt1
de1 do1 2020-11-24 vt2
de1 do2 2020-11-24 vt1
de1 do2 2020-11-24 vt2
I want to get output like below:
col1 col2 col3 vt1 vt2
de1 do1 2020-11-24 1 1
de1 do2 2020-11-24 1 1
I have tried like this
df1 = data.melt('col1','col2','col3').groupby(['col1','col2','col3','col4']).size().unstack(fill_value=0)
I am geeting key error: 'col1'
I have tried with melt(['col1','col2','col3')]
. I am getting error key error: 'col4'
.
Please, help me to solve this.