Pandas (python): How to add column to dataframe for index?
How about:
df['new_col'] = range(1, len(df) + 1)
Alternatively if you want the index to be the ranks and store the original index as a column:
df = df.reset_index()
I stumbled on this question while trying to do the same thing (I think). Here is how I did it:
df['index_col'] = df.index
You can then sort on the new index column, if you like.