1

I am having a excel sheet where I skipped multiple rows and finally arrived at a dataframe with some little structure. But I have a dataframe which looks like this. Bold are headers.

enter image description here

There are some columns on top which I hid in this screenshot as well. While reading a dataframe by skipping rows from excel, there is a multi level indexing. I wanted to have the numbers in header to come as a row. Please advice how to achieve this.

Thank you in advance

3
  • Possible duplicate of Pandas read in table without headers Commented Aug 28, 2019 at 8:18
  • could you add a snipshot from your excel file? Commented Aug 28, 2019 at 8:18
  • Sorry @PV8 cannot add it. its not a duplicate one... because the one in the forum you pointed out, just reads the excel directly by excluding rows. Whereas this is little different. From the dataframe, I need to make the header to row Commented Aug 28, 2019 at 8:20

2 Answers 2

2

You can skip header with header = None if you use .read_csv

df = pd.read_csv(file_path, header=None, usecols=[3,6])

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

2 Comments

not while reading a csv file. Because I also need the headers on top of it which forms multi level indexing.
Can you add a little more insight to your question, please.
1

The following will add your current columns as the last row in the dataframe. You could then put this row into position 0, or rename the columns, if necessary.

row = pd.Series(df.columns, index=df.columns)
df.append(row, ignore_index=True)

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.