Skip to content

Instantly share code, notes, and snippets.

@amaciel81
Created August 7, 2018 03:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save amaciel81/7aa788a22907222fb04c8ee848197310 to your computer and use it in GitHub Desktop.
Save amaciel81/7aa788a22907222fb04c8ee848197310 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