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

python_interest
  • 874
  • 1
  • 9
  • 27
  • Possible duplicate of [Pandas read in table without headers](https://stackoverflow.com/questions/29287224/pandas-read-in-table-without-headers) – Itay Aug 28 '19 at 08:18
  • could you add a snipshot from your excel file? – PV8 Aug 28 '19 at 08: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 – python_interest Aug 28 '19 at 08:20

2 Answers2

2

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

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

MLAlex
  • 142
  • 10
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)
Ted
  • 1,189
  • 8
  • 15