set index to column pandas

# method A
df = df.set_index('col')
# method B
df['col'] = df.index

Here is what the above code is Doing:
1. We’re creating a new column called ‘col’ and setting it equal to the index of the DataFrame.
2. We’re setting the index of the DataFrame to be the column ‘col’.

Note that the order of the steps is important. If you switch the order, you won’t get the desired result.