![](/img/trans.png)
[英]concatenate all sheets in the excel file, some of which have a different skiprows criteria
[英]Import Excel file using skiprows
導入 excel 文件的最佳方法是什么? 我想忽略所有行,直到日期行 8。無論跳過或標題的組合如何,我都無法將第 8 行作為 header。
df = pd.read_excel('sheet.xlsm', skiprows=8, header =1)
df.head(10)
0 col1 col2 Unnamed: 2 Unnamed: 3
1 NaN comm comm1 com2
...
8 NaN NaN 2010-01-01 2010-02-02
然后我嘗試了以下方法,哪種方法有效(為簡單起見,我忽略了數據值):
df.columns = df.iloc[8].values
NaN NaN 2010-01-01 2010-02-02
0
1
但是當我嘗試重命名名為 NaN 的前兩列時,我不能:
df.rename(columns={df.columns[0] :"col1", df.columns[1]: "col2"})
col2 col2 2010-01-01 2010-02-02
0
1
您可以通過以下方式執行此操作:-
首先:-
df=pd.read_excel('sheet.xlsm')
現在提取列值:-
col=df.columns
現在終於:-
df = pd.read_excel('sheet.xlsm', skiprows=8)
df.columns=col
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.