Is there any way to create a CSV file with multiple sheets programmatically in Python?
The xlsxwriter
library is what you're looking for. It can make a workbook with multiple sheets.
Look at the link for tutorials and code.
P.S I am answering this because this is the first result I got when searching on how to do this. Hopefully this helps others.
This worked for me as a conversion from excel to CSV while exporting individual sheet names.
xls = pd.read_excel/csv('file name.xls/csv', sheet_name =['1','2','3','4','5','6','7','8','9','10'])
#list out the sheets you want to export in the bracket above separated by commas and ' '
for sheet_name, df in xls.items():
df['sheets'] = sheet_name
df[['sheets']].to_csv(f'{sheet_name}.csv', header=None)
export_csv = df.to_csv (r'Location you want to export to on your machine',
index = None, header=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With