Pandas DataFrame Add column to index without resetting

We added an append option to set_index. Try that.

The command is:

df.set_index(['d'], append=True)

(we don’t need to specify [‘a’, ‘b’], as they already are in the index and we’re appending to them)

Leave a Comment