Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Reset column index in Pandas to 0,1,2,3...?

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
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Try the following:

df = df.T.reset_index(drop=True).T
over 4 years ago · Santiago Trujillo Report

0

Try replacing the column names:

>>> import numpy as np
>>> import pandas as pd

>>> my_data = [[500292014600, .00, .00, .00, np.nan],
              [500292014600, 100.00, .00, .00, np.nan], 
              [500292014600, 11202.00, .00, .00, np.nan]]
>>> df = pd.DataFrame(my_data, columns=[0,2,3,4,20])
>>> df
              0        2    3    4  20
0  500292014600      0.0  0.0  0.0 NaN
1  500292014600    100.0  0.0  0.0 NaN
2  500292014600  11202.0  0.0  0.0 NaN

>>> df.columns = range(df.shape[1])
>>> df
              0        1    2    3   4
0  500292014600      0.0  0.0  0.0 NaN
1  500292014600    100.0  0.0  0.0 NaN
2  500292014600  11202.0  0.0  0.0 NaN
over 4 years ago · Santiago Trujillo Report

0

In pandas, by index you essentially mean row index. As you can see in your data, the row index is reset after drop and reset_index().

For columns, you need to rename them, you can do something like

data.columns = [ 0,1,2,3,4]
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!