Creating multiple CSV sheets in Python

2020-07-06 02:17发布

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

标签: python csv
4条回答
beautiful°
2楼-- · 2020-07-06 02:23

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.

查看更多
戒情不戒烟
3楼-- · 2020-07-06 02:26

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)
查看更多
别忘想泡老子
4楼-- · 2020-07-06 02:35

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.

查看更多
地球回转人心会变
5楼-- · 2020-07-06 02:40

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.

查看更多
登录 后发表回答