3
                 daysago  line_race rating  rw    wrating
 line_date                                                 
 2007-03-31       62         11     56  1.000000  56.000000
 2007-03-10       83         11     67  1.000000  67.000000
 2007-02-10      111          9     66  1.000000  66.000000S

I was doing an analysis on pandas.dataframe, and i ended up with a dataframe, df, as shown above.

I want to display both line_date and rating. I wanted to do a df['line_date','rating'] but i can't because line_date is technically on the second row.

How do i push line_date to be on the first header row like the rest?

My ideal output:

 line_date        daysago  line_race rating  rw    wrating                                               
 2007-03-31       62         11     56  1.000000  56.000000
 2007-03-10       83         11     67  1.000000  67.000000
 2007-02-10      111          9     66  1.000000  66.000000S

Intuitively, I would remove line 2 such that the data flushes to the top just below the headers, and then I will change the name for col 0. Is there a better way to do it?

1 Answer 1

5

It's not really two lines. The 'line_date' on the "second line" in the left column is actually the name of the column that was made the index.

Just try df.reset_index() (assuming your DataFrame is df); df.reset_index(inplace=True) will do modify it in place (as the parameter implies).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.