Created
August 7, 2018 03:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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