Skip to content

Instantly share code, notes, and snippets.

@sansyrox
Forked from amaciel81/parse_csv.py
Created March 17, 2020 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sansyrox/1f7ffbcf8efea4380db77b82ad425051 to your computer and use it in GitHub Desktop.
Save sansyrox/1f7ffbcf8efea4380db77b82ad425051 to your computer and use it in GitHub Desktop.
Import a CSV file. If condition is met, print two attributes for that condition
from csv import reader as csv_reader
with open("sample_input.csv") as input_fh:
people = csv_reader(input_fh)
headers = next(people)
for row in people:
person = (dict(zip(headers, row)))
if int(person["age"]) >= 30:
print("Name: {name}, City: {city}".format(name=person["name"], city=person["city"]))
name age city
John 30 Chicago
Beth 40 New York
Lucy 25 Los Angeles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment