Consider the following dataframe:
data = {
'A': [0, 0, 0, 1, 1, 1, 1],
'B': list('ABCABCD'),
'C': range(12, 19)
}
pd.DataFrame(data).set_index(['A', 'B'])
C
A B
0 A 12
B 13
C 14
1 A 15
B 16
C 17
D 18
I need to convert this dataframe to
0 1
A 12 15
B 13 16
C 14 17
D NaN 18
Context: I am doing a groupby operation, and the apply
function is return a series. groupby
then converts that to a multi index, but it is easiest for me to represent my data with group labels as columns instead of rows.