How to do it...

Let's use the following sequence of steps to import the data and start our exploration of this dataset in Python:

  1. With the following snippet, we will create a Python list in memory that contains dictionaries of each row, where the keys are the column names (the first row of the CSV contains the header information) and the values are the values for that particular row:
In [3]: import csv    ...: data_file = "../data/income_dist.csv"    ...: with open(data_file, 'r') as csvfile:    ...: reader = csv.DictReader(csvfile)    ...: data = list(reader) 
Note that the input file, income_dist.csv, might be in a different directory in your system depending on where you place it.
  1. We perform a quick check with len to reveal the number of records: ...

Get Practical Data Science Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.