data dict data date list pol list value list import csv with open VK t

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
data= dict()
data= {'date':list(), 'pol':list(), 'value':list()}
import csv
with open ('VK.txt', 'r', encoding='utf8') as csvfile:
stat=csv.reader(csvfile)
for row in stat:
if row[1]=='gender':
data['date'].append(row[0])
data['pol'].append(row[2])
data['value'].append(row[4])
year=set()
for i in data['date']:
year.add(i.split('.')[-1])
M_aged = dict.fromkeys(sorted(year), 0)
W_aged = dict.fromkeys(sorted(year), 0)
for i, date in enumerate (data['date']):
years = data['date'][i].split('.')[-1]
gender_data= data['pol'][i]
if gender_data == 'лю':
M_aged[years] +=(int(data['value'][i]))
else:
W_aged[years] += (int(data['value'][i]))
print(W_aged)
print(M_aged)