0

I have the following codes. I would like to know if the modified dataframe can be started from 0,1,2... so on like regular indexing on Panda.

df = pd.DataFrame([4, 4, 3, 4, 1])
df2 = df[2:4]

where df2 is now-

     0
0    3
2    3

If I would like to access df2 in some regular indexing convention from 0..n, I can't with this approach. Is there some other way that can be done?

Thanks in advance.

Scott Boston
  • 133,446
  • 13
  • 126
  • 161
Touhidul Alam
  • 301
  • 1
  • 11

1 Answers1

2

You can reset the index using reset_index():

df2 = df2.reset_index(drop=True)

For your data, this prints:

>>> print(df2.reset_index(drop=True))
   0
0  3
1  4
pault
  • 37,170
  • 13
  • 92
  • 132