how to fix groupby elimination of index?

Question:

Please see images –

enter image description here
enter image description here

After creating a dataframe, I use groupby, then I reset the index column only to find that the column for ‘county’ is still unseen by the dataframe. Please help to rectify.

Asked By: Charles Xavier

||

Answers:

The df.reset_index() by default is not an "inplace" operation. But with use of the inplace parameter you can make it behave as such.

1. Either use inplace=True

mydf.reset_index(inplace=True)

2. Or save the df into another (or the same) variable –

mydf = mydf.reset_index()

This should fix your issue.

Answered By: Akshay Sehgal
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.