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


Got Something To Say:

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

*