1

I am creating a subset of a dataframe like this:

dist = df['distance'][23:42]

The start index of the result I am getting is then 23, but i want to start the series at index 0.

How can I tell Python to create new indices for my subset and not reuse the ones from the initial dataframe?

Ramona
  • 335
  • 1
  • 5
  • 18

1 Answers1

4

Use .reset_index() with drop=True

drop : bool, default False Do not try to insert index into dataframe columns. This resets the index to the default integer index.

df['distance'].iloc[23:42].reset_index(drop=True)

Or as @yatu suggests:

df.loc[23:42, 'distance'].reset_index(drop=True)
anky
  • 74,114
  • 11
  • 41
  • 70