abc
abc

Reputation: 429

Pandas creating one row of column names for dataframe from multiple column headers in xlsx file

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|....

Upvotes: 0

Views: 329

Answers (1)

IoaTzimas
IoaTzimas

Reputation: 10624

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.

Upvotes: 1

Related Questions