Home > Back-end >  How to reset index of a filtered down dataframe pandas python
How to reset index of a filtered down dataframe pandas python

Time:06-11

Good morning,

This is the outpout of my DataFrame:

print(df_OIH)

      VolumeOIH
1         84673
79        42034
157       64202
235      260018
313       79126
...         ...
5071      58842
5149     118051
5227      35798
5305      68584
5383      90627

[70 rows x 1 columns]

As you can see the row jumps from 1 to 79. I intended to merge this DataFrame with another one but before doing so I want it to be in order so the first row is row #1, the 2nd row would be row#2 etc. I am learning pandas on my own, did not go to school. Is this first column called index and if yes how do I order it?

Thank you

CodePudding user response:

The output you're showing is instance of a pandas.Series object, which is basically a dataframe with one column field (and the index). In order to reset the indices, you can use the pandas.Series.reset_index function with the drop parameter set to "True":

df_OIH['VolumeOIH'].reset_index(drop=True)
  • Related