4 ms·
Apart from grouping, custom indexes are great as default columns for joins. I just wish Pandas treated named index columns as columns. When I write df["blah"],
by ilyagr 5y ago
Apart from grouping, custom indexes are great as default columns for joins.
I just wish Pandas treated named index columns as columns. When I write df["blah"], I don't want to have to remember whether I just loaded the data and it's a normal column or if I just grouped on "blah" and it's an index column.
Currently, in the latter case, subscripting doesn't work and you either have to do a reset_index() or look up the correct incantation -- something like df.index.get_level("blah").
I have a feeling that the root of the problem is that Pandas ended up the same concept of "index" both for optimized lookup and for the UI of grouping / joining. My guess is that get_level is less efficient than it should be, and thus Pandas discourages using it by making it obscure.