Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset Column Index Pandas?

Tags:

python

pandas

How do I go about resetting the index of my dataframe columns to 0,1,2,3,4?

(How come doing df.reset_index() doesn't reset the column index?)

>>> data = data.drop(data.columns[[1,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]], axis=1) >>> data = data.drop(data.index[[0,1]],axis = 0) >>> print(data.head())              0         2    3    4    20 2  500292014600       .00  .00  .00  NaN 3  500292014600    100.00  .00  .00  NaN 4  500292014600  11202.00  .00  .00  NaN >>> data = data.reset_index(drop = True) >>> print(data.head())               0         2    3    4    20  0  500292014600       .00  .00  .00  NaN  1  500292014600    100.00  .00  .00  NaN  2  500292014600  11202.00  .00  .00  NaN 
like image 377
MrClean Avatar asked Feb 16 '17 21:02

MrClean


People also ask

What is reset index in pandas?

Pandas DataFrame reset_index() Method The reset_index() method allows you reset the index back to the default 0, 1, 2 etc indexes. By default this method will keep the "old" idexes in a column named "index", to avoid this, use the drop parameter.

How do I reset a DataFrame index?

Use DataFrame.reset_index() function We can use DataFrame. reset_index() to reset the index of the updated DataFrame. By default, it adds the current row index as a new column called 'index' in DataFrame, and it will create a new row index as a range of numbers starting at 0.


1 Answers

Try the following:

df = df.T.reset_index(drop=True).T 
like image 126
Pablo Fonseca Avatar answered Sep 16 '22 15:09

Pablo Fonseca