["python","pandas"]
Fill a new pandas column with row numbers

I have the following DataFrame data with random index values: A B 100 0 7 203 5 4 5992 0 10 2003 9 8 20 10 5 12 6 2 I would like to add a new column 'C' with row numbers. For example: A B C 100 0 7 0 203 5 4 1 5992 0 10 2 2003 9 8 3 20 10 5 4 12 6 2 5
Use numpy.arange or range by length of DataFrame: df['C'] = np.arange(len(df)) df['C'] = range(len(df)) Or you can use DataFrame.shape, thank you @Mehmet Burak Sayıcı: df['C'] = np.arange(df.shape[0]) print (df) A B C 100 0 7 0 203 5 4 1 5992 0 10 2 2003 9 8 3 20 10 5 4 12 6 2 5