I have a dataframe:
index col1 col2 col3
0 X A 123
1 X A 456
2 X B 654
3 X B 321
4 X A 111
I'm trying to use pivot_table
to get this df into the following format:
index A B
0 123 654
1 456 321
2 111 NaN
I'm trying to use... pivot_table(index=df.index, columns=['col2'], values='col3')
, however this just ends up in the following state:
index A B
0 123 NaN
1 456 NaN
2 111 NaN
3 NaN 654
4 NaN 321
How can I avoid this?