I have a long list of dictionaries like this:
dict_data = [{'country': 'canada', 'province': 'alberta', 'city': 'calgary', 'sales': 1450, 'date': ['14', '02', '2021']}, {'country': 'canada', 'province': 'ontario', 'city': 'toronto', 'sales': 2003, 'date': ['12', '02', '2021']}]
I need to filter the sales data by month to perform calculations on them. But I am stuck on how to access dictionary values by key, when the values are a list. To start with I am trying to convert the date strings into integers.
for row in dict_data:
row['date'] = int(row['date'])
I get an error "TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'". Similar to this method worked for splitting the date up into separate strings.
I thought I would be able to access the list values for date by using something along the lines of dict_data['date'][1] to access the month, but that doesn't work either, I am assuming because I have a list of dictionaries and not just one? Do I need to iterate through the list of dictionaries and how do I do that?