Home > Blockchain >  how to start from 1 in dataframe
how to start from 1 in dataframe

Time:10-16

i have dataframe that i would like to start my row from 1 instead of 0.

For example, if you can see the picture.

enter image description here

CodePudding user response:

Use DataFrame.index and specify range from 1 to length(dataframe) 1

DF = pd.read_csv("path")
DF.index = np.arange(1, len(DF)   1)

CodePudding user response:

You can set the index to whatever you like, but it's probably easier to index from 0

>>> import pandas as pd
>>> df = pd.DataFrame({"a": ["foo", "bar"]})
>>> df
     a
0  foo
1  bar
>>> df.index = df.index   1
>>> df
     a
1  foo
2  bar
  • Related