I am looking for a pythonic and concise way to select a column in a .csv file and store all cells of the column in, e.g., a list.
import csv
with open("/path/to/file.csv","r") as csvfile:
reader = csv.DictReader(csvfile, delimiter=";")
# TODO: select column for key "foo"
# TODO: select column for key "bar"
# TODO:store "foo" data in list
# TODO: store "bar" data in list
It’s straightforward to get columns out of DictReader row dicts in pure Python, and someone else is probably writing an answer to that effect right now, so instead of duplicating that effort I’ll show how to do this in one of my favourite Python libraries for data manipulation, pandas:
In the dark pre-
pandasdays I had my own hand-crafted library for this kind of data access. After about fifteen minutes withpandasa few years ago I tossed it..