Recently I have posted a problem regarding writing a spilted dataframe into different excel sheets this post, and I somehow find an answer which resulted in writing each of them in a separate excel file rather than separate excel sheets. I have also read the recommended post here but that also was not much help. I am wondering if I could find a solution to my question and I really feel that it is not that much complicated but since I am new in this field, I could not find it.
Asked
Active
Viewed 39 times
1 Answers
1
Combining solutions from both the links that you posted, here is the solution
# define an excel writer first
writer = pd.ExcelWriter("output.xlsx", engine = 'xlsxwriter')
df_split = np.array_split(promotion1, 4)
for index, df_sub in enumerate(df_split):
#print(df_sub.head())
# save each of your splitted dataframes using excel writer
df_sub.to_excel(writer, sheet_name = 'sheet' + str(index))

MNA
- 183
- 2
- 8
-
problem solved:) thanks. however since I am new to python and coding, I am wondering if you could say the difference between using simply df.to_excel() and creating a writer object and using an engine? – mpy Sep 12 '19 at 06:12
-
1df.to_excel will create new excel file every time you execute it. However, by using writer object you can add new sheets to existing excel file – MNA Sep 12 '19 at 07:47