16

Is there any way to create a CSV file with multiple sheets programmatically in Python?

4 Answers 4

18

Multiple CSV files. One CSV file per sheet.

A comma seperated value file is a plain text format. It is only going to be able to represent flat data, such as a table (or a 'Sheet')

For storing multiple sheets, you should use separate CSV files. You can write each one separately and import/parse them individually into their destination.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks slackware, I understand now
7

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.

Comments

2

Not sure what you are trying to do with Multiple Sheets of CSV's. Let me elaborate my thinking on this.

  1. Maybe you want a folder with different CSV files in it.
  2. If you "can" use XML then probably you may want to have XML sheet in a big XML "Workbook".

Haven't seen multiple sheets of csv yet.

Comments

1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.