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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.