I have a dataframe with 4 columns co1
, col2
, col3
and col4
. I need to:
- Group dataframe based on key
col1
andcol2
- Then group other columns like
col3
andcol4
and display counts forcol3
andcol4
.
Input
col1 col2 col3 col4
1 1 2 4
1 1 2 4
1 1 3 5
Output
col1 col2 col_name col_value cnt
1 1 col3 2 2
1 1 col3 3 1
1 1 col4 4 2
1 1 col4 5 1
Is this possible?