data dict data ages 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= {'ages':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_age':
data['ages'].append(row[3])
data['pol'].append(row[2])
data['value'].append(row[4])
ages=set()
for i in data['ages']:
ages.add(i)
M_aged = dict.fromkeys(sorted(ages), 0)
W_aged = dict.fromkeys(sorted(ages), 0)
for i, date in enumerate (data['ages']):
my_age = data['ages'][i]
gender_data= data['pol'][i]
if gender_data == 'лю':
M_aged[my_age] +=(int(data['value'][i]))
else:
W_aged[my_age] += (int(data['value'][i]))
print(W_aged)
print(M_aged)