简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM