Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
MultiIndex.set_labels() function set new labels on MultiIndex. Defaults to returning new index.
Syntax: MultiIndex.set_labels(labels, level=None, inplace=False, verify_integrity=True)
labels : new labels to apply
level : level(s) to set (None for all levels)
inplace : if True, mutates in place
verify_integrity : if True, checks that levels and labels are compatible
Returns: new index (of same type and class…etc)
Example #1: Use
MultiIndex.set_labels() function to reset the lables of the MultiIndex.
Now let’s reset the labels of the MultiIndex.
As we can see in the output, the labels of the MultiIndex has been reset.
Example #2: Use
MultiIndex.set_labels() function to reset any specific label only in the MultiIndex.
Now let’s reset the ‘Char’ label of the MultiIndex.
As we can see in the output, the ‘Char’ label of the MultiIndex has been reset to the desired value.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course