-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathev_counts_monthly.py
More file actions
48 lines (39 loc) · 1.2 KB
/
ev_counts_monthly.py
File metadata and controls
48 lines (39 loc) · 1.2 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import csv
filename = 'henkiloautot-sahko-merkit.csv'
all_rows = []
csv_file = open(filename)
reader = csv.reader(csv_file)
headers = next(reader)
for row in reader:
if row[0] in ['M1', 'M1G']:
all_rows.append(row)
csv_file.close()
print(len(all_rows))
years = range(2016, 2026)
counts = {}
for row in all_rows:
if row[1] == '': # ohita tyhjä rek. pvm
continue
# registration date is DD.MM.YYYY
year = int(row[1][6:]) # irrota rek. vuosi
if year < years.start: # ohita liian vanha
continue
if year not in counts: # tee uusi lista vuodelle
counts[year] = [0] * 12
month = int(row[1][3:5]) - 1 # irrota rek. kuukausi
counts[year][month] += 1
print(f'Sähköautojen ensirekisteröinnit {years.start} - {years.stop - 1}')
for year in years:
print(f'{year}: {sum(counts[year]):>5}')
for month in range(12):
print(f'\t{month+1:>2}: {counts[year][month]}')
print(f'Yhteensä: {len(all_rows)}')
import matplotlib.pyplot as plt
labels = []
values = []
for year in years:
for month in range(12):
labels.append(f'{year}\n-{month+1}')
values.append(counts[year][month])
plt.bar(labels, values, tick_label=labels)
plt.show()