pandas method of regenerating index

  • 2021-01-25 07:36:10
  • OfStack

In the process of data processing, there is such a problem. Filtering some data, the index starts from more than 600, but I want the index of this row to start from 0.

At this point, I thought:


df.reindex(range(length))

However, after I checked the first data, I found that all the values between 0 and 624 were Nan, which was obviously not the data I needed.

Finally I found the instructions:

ES11en calls the ES12en method and rearranges it according to the new index, introducing an index value if it does not currently exist

Missing value; You can use the fill_value parameter to fill in the default value, or you can use the method parameter to set the filling method;

Thanks to the help of colleagues around me, I found a solution:

df_new = df.set_index(drop=True)

The effect after that is that the expected 625 rows of data are now subscripts starting at 0.


Related articles: