I have a big dataset (df) (8M rows, 50 columns). I am trying to build a for loop to create an excel file where each sheet holds the value_counts() of each of the column of the dataset.
(i.e. on worksheet('Sheet1') I write df.columns[0].value_counts() and on worksheet('Sheet2') I write df.columns[1].value_counts() etc etc).
Here's what I tried:
for i in range(3,6): # I am using a small range to test the loop
z = df1[df1.columns[i]].value_counts()
z = z.to_frame().reset_index()
title = str(i)
with pd.ExcelWriter('Pivot part1.xlsx') as writer:
z.to_excel(writer, sheet_name=title)
This keeps overwrite the file so that I ended up with an excel file with only one sheet rather the an Excel file with 4 sheets.
I hope I managed to explain clearly the issue and I apologize if this question is a duplicate, but I couldn't find a suitable answer, or at least one I could understand.