Ways to convert a CSV file to Excel file in Python 3

python-ways-to-convert-csv-to-excel-file-python-3-feature-image

In this tutorials, we’re gonna look at 4 ways to convert a CSV file to Excel file in Python 3. With each way, we use one of these module: xlwt, xlsxwriter, openpyxl and pandas.

Related Posts:
How to read/write CSV files in Python
How to read/write Excel files in Python
Node.js Extract MySQL Data to Excel(.xlsx) File – using exceljs

Convert CSV file to Excel file using xlwt

With this method, we:
– use csv module to open and read CSV file
– then use xlwt module to write and save Excel file

*Note: xlwt can only export Excel .xls files, not .xlsx files.

Example code:

Convert CSV file to Excel file using xlsxwriter

With this method, we:
– use csv module to open and read CSV file
– then use xlsxwriter module to write and save Excel file

Example code:

Convert CSV file to Excel file using openpyxl

With this method, we:
– use csv module to open and read CSV file
– then use openpyxl module to write and save Excel file

Example code:

Convert CSV file to Excel file using pandas

With this method, we use only one module pandas to read Excel file and write data to CSV file.

Example code:



By grokonez | March 9, 2019.


Related Posts


7 thoughts on “Ways to convert a CSV file to Excel file in Python 3”

  1. In Step 3, enter your email address. The only reason you’re doing this is to receive your converted file. They won’t bombard you with mail and your information won’t be sold.

  2. Adding an answer that exclusively uses the pandas library to read in a .csv file and save as a .xlsx file. This example makes use of

  3. from openpyxl import Workbook import csv wb = Workbook() ws = wb.active with open(‘test.csv’, ‘r’) as f: for row in csv.reader(f): ws.append(row) wb.save(‘name.xlsx’)

  4. The fully reproducible example uses numpy to generate random numbers only, and this can be removed if you would like to use your own .csv file.

  5. Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

  6. Pretty easy, right? If you can manage to do this then you’re a perfect fit for the Masters of Excel course (it’s for beginners and intermediate users). You can learn to do so much more!

  7. Thanks for this, it helped me out a lot!
    Is there a typo on the description for the pandas method?
    You wrote: With this method, we use only one module pandas to read Excel file and write data to CSV file.
    I thought it would be: With this method, we use only one module pandas to read CSV file and write data to Excel file.

Got Something To Say:

Your email address will not be published. Required fields are marked *

*