1

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!

5
  • You are going to have to open the file.. how else would you read/write to the file? Commented Nov 2, 2017 at 16:21
  • You know you can decide where the start row to input the data in excel right ? Commented Nov 2, 2017 at 16:29
  • @Wen yes, but i still need to add some extra empty rows at the top or middle, etc. Commented Nov 2, 2017 at 16:36
  • @Farhan.K read about pandas ;D. Commented Nov 2, 2017 at 16:42
  • Add empty row at particular index without replacing row values use : df1 = pd.DataFrame(np.insert(df1.values, index+1, values=[" "] * len(df1.columns), axis=0),columns = df1.columns) Commented Feb 1, 2019 at 7:32

2 Answers 2

4

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')
Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

Thanks, i saw that answer on another post but i still got problems with that.
@Danitsu, what kind of problems?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.