Raúl Casado
Raúl Casado

Reputation: 445

Add empty rows at the beginning of dataframe before export to xlsx

I have a pandas dataframe and I need to append 3 blank rows over the head of the columns before to export it to xlsx.

I'm using this code based on this question:

df1 = pd.DataFrame([[np.nan] * len(df.columns)], columns=df.columns)
df = df1.append(df, ignore_index=True)

But it adds the rows at index 0 and I need the blank rows before the row with the column names in the xlsx.

Is this possible to do?

Upvotes: 2

Views: 915

Answers (1)

jezrael
jezrael

Reputation: 863246

Use startrow parameter for omit first N rows:

N = 3
df.to_excel('data.xlsx', sheet_name='Sheet1', startrow=N, index=False)

Upvotes: 1

Related Questions