forked from epfl-ada/Projects
-
Notifications
You must be signed in to change notification settings - Fork 2
/
map_france_helpers.py
36 lines (29 loc) · 1.09 KB
/
map_france_helpers.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
from data_loading import *
import numpy as np
import seaborn as sns
import math
import matplotlib.pyplot as plt
def get_dep_count_df(data):
"""Create a DataFrame (dep, count) counting number of injuries per depertment.
Parameters
----------
data : YearLoader
Dataset loading class.
Returns
-------
pandas.DataFrame
dep_count DataFrame.
"""
characteristics = data.get_dataframe('characteristics')
# Format dep
# Remove 0 at the end of dep number if the dep number is not DOM-TOM
characteristics['dep'] = characteristics.apply(lambda x: x.dep//10 if x.dep<971 else x.dep, axis=1)
# Add 0 in front of dep number if dep number is lower than 10
characteristics['dep'] = characteristics.apply(lambda x: '0'+str(x.dep) if x.dep<10 else str(x.dep), axis=1)
# Count values per dep
dep_count = pd.DataFrame(characteristics['dep'].value_counts())
dep_count.reset_index(level=0, inplace=True)
dep_count.rename(columns={'index':'dep',
'dep':'count'},
inplace=True)
return dep_count