You can use the append_df_to_excel()
helper function, which is defined in this answer:
Demo:
In [127]: df = pd.DataFrame(np.random.rand(5, 3), columns=list('abc'))
In [128]: df
Out[128]:
a b c
0 0.597353 0.770586 0.671231
1 0.628605 0.161283 0.397493
2 0.476206 0.701582 0.476809
3 0.045590 0.302834 0.857033
4 0.414820 0.478016 0.563258
In [129]: df.to_excel(filename)
In [130]: append_df_to_excel(filename, df, sheet_name="Sheet2", startrow=1, startcol=1)
In [131]: append_df_to_excel(filename, df, sheet_name="Sheet3", index=False)
In [132]: append_df_to_excel(filename, df, sheet_name="Sheet1", startcol=2, index=False)
Result:
Sheet1:
Sheet2:
Sheet3:
PS tested using the following versions:
- python: 3.6.4
- pandas: 0.22.0
- openpyxl: 2.4.10
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…