pandas convert row names to column

Solutions on MaxInterview for pandas convert row names to column by the best coders in the world

showing results for - "pandas convert row names to column"
Valentina
26 Oct 2018
1# Basic syntax:
2df.index.name = 'new_column_name'
3df.reset_index(inplace=True)
4
5# Example usage:
6import pandas as pd
7
8print(df)
9
10     head1  head2  head3
11bar     32      3    100
12bix     22    NaN    NaN
13foo     11      1    NaN
14qux    NaN     10    NaN
15xoo    NaN      2     20
16
17df.index.name = 'new_column_name'
18df.reset_index(inplace=True)
19
20print(df)
21
22  	new_column_name  head1  head2  head3
230     			bar     32      3    100
241     			bix     22    NaN    NaN
252     			foo     11      1    NaN
263     			qux    NaN     10    NaN
274     			xoo    NaN      2     20