thomassantosh thomassantosh - 5 months ago 19
Python Question

Labeling indexes on a dataframe

I have a multi-layer index in a dataframe. When I run

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?

Answer Source

Either

b.rename_axis(['X', 'Y', 'Z'])

Or

b.index.names = ['X', 'Y', 'Z']