I have the following dataframe, where I want to rename the index fromsummary
to id
:
summary student count
0 error 6
1 yes 1
2 no 1
3 other 9
I have tried:
newdf = df.reset_index().rename(columns={df.index.name:'foo'})
which gives:
summary index student count
0 0 error 6
1 1 yes 1
2 2 no 1
3 3 other 9
I have also tried: df.index.rename('foo', inplace = True)
which gives:
summary student count
foo
0 error 6
1 yes 1
2 no 1
3 other 9
I have also tried: df.rename_axis('why', inplace = True)
which gives:
summary student count
why
0 error 6
1 yes 1
2 no 1
3 other 9
When I do df.dtypes
:
summary
student object
count init64
dtype: object
What I would like:
id student count
0 error 6
1 yes 1
2 no 1
3 other 9
OR:
student count
0 error 6
1 yes 1
2 no 1
3 other 9