Marking indexes on a data frame
I have a multilevel index on a dataframe. When I ran
print(len(b.index.names))
I get 3. When I run
print(b.index.names)
I get [None, None, None].
How do I give each of the above index levels a unique name?
+3
thomassantosh
source
to share
2 answers
Or
b.rename_axis(['X', 'Y', 'Z'])
or
b.index.names = ['X', 'Y', 'Z']
+2
piRSquared
source
to share
You can also assign with such a list so that the indices are named index_1
, index_2
and index_3
accordingly if more they are also named accordingly:
b.index.names = ["index_" + str(i+1) for i in range(len(b.index.names))]
+1
0p3n5ourcE
source
to share