import json data date list pol list value list import csv with open VK

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import json
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])
aged = dict.fromkeys(sorted(year), {"М": 0, "Ж": 0})
j = json.loads(json.dumps(aged))
for i, date in enumerate (data['date']):
years= data['date'][i].split('.')[-1]
gender_data= data['pol'][i]
value= int(data['value'][i])
j[years][gender_data]+= value
print(j)