-
Notifications
You must be signed in to change notification settings - Fork 3
/
vigilo_streets.py
64 lines (47 loc) · 1.79 KB
/
vigilo_streets.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import textwrap
import requests
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
MIN_COUNT = 5 # Minimum number of observation per street
# Getting data
resp = requests.get('https://vigilo.jesuisundesdeux.org/get_issues.php')
df = pd.DataFrame(resp.json())
resp = requests.get('https://vigilo.jesuisundesdeux.org/get_categories.php')
cat = resp.json()
cat['2'] = cat['2'].replace(' (gcum)', '')
df.address = df.address.apply(lambda x: x.split(',')[0])
df.address = df.address.apply(lambda x: x.replace('Avenue', 'Av.').
replace('Boulevard', 'Bd.').
replace('Professeur', 'Pr.').
replace('Faubourg', 'Fb.').
replace('Gabriel Buchet', ''))
df = df.replace({'categorie': cat})
streets = df.groupby(by='address').token.count()
streets = streets.sort_values(ascending=False)
df.address = df.address.apply(lambda x: x if streets[x] > MIN_COUNT else 'Autre')
categories = df.groupby(by='categorie').token.count()
categories = categories.sort_values(ascending=False)
tab = pd.crosstab(df.address, df.categorie, margins=True, margins_name='Total')
tab = tab.sort_values(by='Total', ascending=False)
cols = list(tab)
cols.remove('Autre')
cols.remove('Total')
cols.append('Autre')
cols.append('Total')
rows = list(tab.index)
rows.remove('Autre')
rows.remove('Total')
rows.append('Autre')
rows.append('Total')
tab = tab.loc[rows, cols]
fig, ax = plt.subplots(figsize=(8, 8))
sns.heatmap(tab, annot=tab.applymap(lambda x: '' if x == 0 else str(x)),
cbar=False, fmt='s', ax=ax, cmap="YlGnBu", vmin=0, vmax=50)
plt.ylabel('')
plt.xlabel('')
# plt.xticks(rotation=70)
plt.title("Principales localisations des observations de Vǐgǐlo")
plt.tight_layout()
plt.show()
a = 0