Generate row number in pandas python

In order to generate row number in pandas python we need to add the index to a constant of our choice. Let’s see how to

  • Generate row number in pandas python

First let’s create a dataframe

import pandas as pd
import numpy as np

df1 = {
    'State':['Arizona','Georgia','Newyork','Indiana','Florida'],
   'Score1':[4,47,55,74,31]}

df1 = pd.DataFrame(df1,columns=['State','Score1'])
print(df1)

df1 will be

Generate row number in pandas python 1

 

We need to add a value (here 430) to the index to generate row number and the result is stored in a new column as shown below.


df1['New_ID'] = df1.index + 430
print(df1)

So the resultant dataframe will be

Generate row number in pandas python 2

 

p Generate row number in pandas python                                                                                                                n Generate row number in pandas python