简体   繁体   English

使用python pandas在excel中添加空行

[英]Add empty row in excel using python pandas

I want to add an empty row to all of my excel files using python pandas.我想使用 python pandas 向我的所有 excel 文件添加一个空行。

I leave you an example so you can understand.我给你举个例子你就明白了。


I have this: Excel example我有这个: Excel示例

在此处输入图片说明


And I want to add this row before name and city: Example我想在名称和城市之前添加这一行:示例

在此处输入图片说明


I need to do that, but not opening the excels files cause this is just a small example of what I really need.我需要这样做,但不要打开 excels 文件,因为这只是我真正需要的一个小例子。

Thanks!谢谢!

You can use startrow for this您可以为此使用 startrow

writer = pd.ExcelWriter('demo.xlsx')
df.to_excel(writer, sheet_name='Concentrado',startrow=1, startcol= 1, encoding='utf-8')

Demo:演示:

In [107]: df
Out[107]:
   a    b
0  a  zzz
1  b  yyy

In [108]: pd.DataFrame([[''] * len(df.columns)], columns=df.columns).append(df)
Out[108]:
   a    b
0
0  a  zzz
1  b  yyy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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