简体   繁体   中英

Mix of columns in excel to one colum with Pandas

I have to import this Excel in code and I would like to unify the multi-index in a single column. I would like to delete the unnamed columns and unify everything into one. I don't know if it's possible.

表格

I have tried the following and it imports, but the output is not as expected. I add the code here too

import pandas as pd
import numpy as np

macro = pd.read_excel(nameExcel, sheet_name=nameSheet, skiprows=3, header=[1,3,4])
macro = macro[macro.columns[1:]]
macro

代码尝试

The way to solve it is to save another header of the same length as the previous header.

cols = [...]
if len(df1.columns) == len(cols):
   df1.columns = cols
else:
   print("error")

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