I am pivoting a dataframe.
df_features = df_features.pivot(index='filename', columns='code', values='frequency')
but when I do so the index field which is filename gets missing!
my dataframe is like this
filename code frequency
F1 X1 3
F1 X2 6
F1 X3 4
F2 X1 7
F2 X4 9
F3 X2 1
F3 X3 5
F4 X1 3
F4 X3 4
F4 X4 3
F5 X3 2
after Pivoting It should look like this
filename X1 X2 X3 X4
F1 3 6 4 0
F2 7 0 0 9
F3 0 1 5 0
F4 3 0 4 3
F5 0 0 2 0
But what I acually Get is
X1 X2 X3 X4
3 6 4 0
7 0 0 9
0 1 5 0
3 0 4 3
0 0 2 0
my question is how to include filename in the pivoted dataframe?
Edit :
This is how the data look like in another example after pivoting
alothough I can see file name in the columns!!! yet when I try this code I get error
df_features["filename" ]
KeyError: 'filename'
