Working with CSVs
Recipe Difficulty: Easy
Python Version: 2.7 or 3.5
Operating System: Any
Everyone has reviewed data in a CSV spreadsheet at some point. They are pervasive and a common output format for most applications. Writing CSVs with Python is one of the easiest methods to create a report of processed data. In this recipe, we will demonstrate how you can use the csv
and unicodecsv
libraries to create quick reports with Python.
Getting started
Part of this recipe uses the unicodecsv
module. This module replaces the built-in Python 2 csv
module and adds Unicode support. Python 3's csv
module does not have this limitation and can be used without the support of any additional library. All other libraries used in this script are present in Python's standard library. The unicodecsv
library can be installed with pip
:
pip install unicodecsv==0.14.1
Note
To learn more about the unicodecsv
library, visit https://github.com/jdunck/python-unicodecsv.
How to do it...
We follow these steps to create CSV...