0

I wanted to create just one row of column names in the data frame but ended up with a weird format:

pd.read_excel('filename.xlsx', sheet_name = 'sheetnamehere', skiprows = 4, nrows = 60, header = [0,2])

Is it possible to create a data frame with just one row of column names in the following format?

Quarter|America|Southeast Asia|Greater China|North Asia|South Asia|....

abc
  • 399
  • 4
  • 18
  • if you have one hader, you will have one column too. Is this what you want to achieve? – IoaTzimas Sep 05 '20 at 08:50
  • rephrased my question. I meant creating just one row of column names for the data frame – abc Sep 05 '20 at 08:54
  • Does this answer your question? [Read excel sheet with multiple header using Pandas](https://stackoverflow.com/questions/40554106/read-excel-sheet-with-multiple-header-using-pandas) – Nicolò Gasparini Sep 05 '20 at 09:04

1 Answers1

1

If the rest of your data is ok, best way is to define your columns after df creation with

df.columns=['Quarter', 'America', 'Southeast Asia', 'Greater China' ,'North Asia','South Asia',... etc]

If rest of the data is loaded weirdly, please paste a bigger sample so that we will investigate.

IoaTzimas
  • 10,538
  • 2
  • 13
  • 30
  • This answered my question, I didn't think of just defining the columns after creating the data frame – abc Sep 05 '20 at 09:16