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:
JavaScript
x
3
1
df1 = pd.DataFrame([[np.nan] * len(df.columns)], columns=df.columns)
2
df = df1.append(df, ignore_index=True)
3
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?
Advertisement
Answer
Use startrow
parameter for omit first N
rows:
JavaScript
1
3
1
N = 3
2
df.to_excel('data.xlsx', sheet_name='Sheet1', startrow=N, index=False)
3