Pandas DataFrame Length is less than Max Index

Viewed 280

I have an issue that I do not understand. As shown in the code block below, the number of rows in my dataframe is significantly less than the max index of the data frame. I have repeatedly done...

npr.reset_index(drop=True)

...to no avail. If you could help me understand how this is possible, I'd appreciate it. Thanks!

len(npr.episode)
Out[620]: **3199296**
   
np.shape(npr)
Out[622]: (**3199296**, 7)

npr.index
Out[623]: 
Int64Index([      0,       1,       2,       3,       4,       5,       6,
                  7,       8,       9,
            ...
            3199848, 3199849, 3199850, 3199851, 3199852, 3199853, 3199854,
            3199855, 3199856, **3199857**],
           dtype='int64', length=3199296)
1 Answers

You either have to reassign the results of the drop_index like this npr = npr.reset_index(drop=True) or you have to do it in place npr.reset_index(drop=True, inplace=True) as the default of reset_index is to create a new DataFrame object that you need to assign to a variable.

Related