Exporting data to JSON, CSV, and Excel
While, as producers of data visualization, we are mostly using other people's data; importing and reading data are major activities. We do need to write or export data that we produced or processed, whether it is for our or others' current or future use.
We will demonstrate how to use the previously mentioned Python modules to import, export, and write data to various formats such as JSON, CSV, and XLSX.
For demonstration purposes, we are using the pregenerated dataset from the Importing data from fixed-width datafiles recipe.
Getting ready
For the Excel writing part, we will need to install the xlwt
module (inside our virtual environment) by executing the following command:
$ pip install xlwt
How to do it...
We will present one code sample that contains all the formats that we want to demonstrate: CSV, JSON, and XLSX. The main part of the program accepts the input and calls appropriate functions to transform data. We will walk through separate sections...