'how to print dictionary row data by two values
I'm pretty new in python and i have a question regarding dictionary. i would like to check if two values "day" and "month" are exist in one of the dictionary data rows. if they are, i would like to print the desired row data in the dictionary. i only succeeded one value "day" or "month" but not both. any idea how to do it?
#birthday.csv file:
name,email,year,month,day
Test1,[email protected],1961,03,25
Test2,[email protected],1977,03,21
#python code:
import pandas
import datetime as dt
now = dt.datetime.now()
day = int(now.strftime("%d"))
month = int(now.strftime("%m"))
with open("birthdays.csv") as read_file:
read = pandas.read_csv(read_file)
dictionary = read.to_dict('list')
print(dictionary)
output:
{'name': ['Test1', 'Test2'], 'email': ['[email protected]', '[email protected]'], 'year': [1961, 1977], 'month': [3, 3], 'day': [25, 21]}
i tried:
if str(month) in str(dictionary['month']) and str(day) in str(dictionary['day']):
i do not know how to print the data row in this way that if for example "day and "month" are in the row:Test2,[email protected],1977,03,21 it will print this row.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
