Reputation: 2253
Is there any advantage to using another name for the index of a pandas DataFrame/Series? If I use df[index_name]
, it doesn't work. Pandas docs on MultiIndex has an example where the indices have names, but the names are not used at all in slicing or selecting data. If you're not printing the dataframe, what's the use of changing the index name?
Upvotes: 2
Views: 252
Reputation: 2953
There are scenarios where you create an index from a column. In these cases, in new versions of Pandas (i believe 0.22 and above), Pandas names the index the same as the column is was copied from. Then when you try to do something, the two can conflict and from what I can see in Pandas 0.24 you cannot manipulate a dataframe (i.e. sort_values('columnname_sameas_indexname'). Really quite a problem for me as I have many indices that are created from a column, and now that i updated to 0.24, my code fails (until I go rename all these damn indices...)
Upvotes: 1