CSV files: reader and writer
CSV (*Comma-Separated Values*) is the simplest format to store tables of data: each line is a row and the values of each row are…
CSV and JSON are the two most widely used data formats in practice. In this lesson you will learn how to read and write CSV files with the csv module, including headers and fields with commas, and how to convert Python data to JSON and back with the json module. You will also learn to handle errors and to choose the right format, with practical exercises.
CSV (*Comma-Separated Values*) is the simplest format to store tables of data: each line is a row and the values of each row are…
Accessing columns by position ( row[2] ) is awkward and error-prone: if you add a column, all the numbers change. DictReader and…
JSON (*JavaScript Object Notation*) is the standard format for exchanging data between programs, especially on the internet: web…
To save JSON in a file and read it later you use json.dump and json.load , without the final "s": they work directly with files…
Both formats serve to store data as text, but they solve different problems. Choosing the format well makes the rest of the…
Create a Python program that reads lines in CSV format and adds up one of their columns with the csv module.
Create a Python program that reads CSV lines whose fields may contain commas, thanks to the quotes.
Create a Python program that reads a CSV with a header and shows the people of a city using csv.DictReader .
Create a Python program that generates a CSV with csv.writer , letting the module take care of the quotes.
Create a Python program that reads a JSON object and shows some of its data with the json module.
Create a Python program that calculates the total of an order stored as a JSON list.
Create a Python program that builds a dictionary and converts it into JSON text with json.dumps .
Create a Python program that analyzes a JSON with nested data.
Create a Python program that checks whether a text is valid JSON, catching the error raised by json.loads .
Create a Python program that converts data in CSV format to JSON.