Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reset axis 1 in pandas?

Tags:

pandas

I want to reset my column headers in pandas. I want my column names to be my top row and then my column headers to be reset to 0,1,2,3 in pandas dataframe. How do i perform this operation?

like image 330
stormtrooper12 Avatar asked Sep 05 '25 03:09

stormtrooper12


2 Answers

one-liner

df.T.reset_index().T
like image 64
piRSquared Avatar answered Sep 09 '25 17:09

piRSquared


You can change the column header names with .columns property of pandas dataframe. To reset it to 0,1,2,3.. use the following code

>>> df.columns = list(range(len(df.columns)))
like image 41
Asad Mahmood Avatar answered Sep 09 '25 17:09

Asad Mahmood