Danitsu
Danitsu

Reputation: 45

Add empty row in excel using python pandas

I want to add an empty row to all of my excel files using python pandas.

I leave you an example so you can understand.


I have this: Excel example

enter image description here


And I want to add this row before name and city: Example

enter image description here


I need to do that, but not opening the excels files cause this is just a small example of what I really need.

Thanks!

Upvotes: 1

Views: 5135

Answers (2)

asterCraker
asterCraker

Reputation: 71

You can use startrow for this

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

Upvotes: 4

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210912

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

Upvotes: 1

Related Questions