Col1
is the field that will be the "rows" indexCol2
is the column whose values will become the new columnsCol3
is any other column (assuming that other columns are always filled;.count()
will only count cells whereCol3
has a value)
df \
.groupby(['Col1', 'Col2']) \
[['Col3']] \
.count() \
.reset_index() \
.pivot('Col1', 'Col2', 'Col3')