import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['figure.dpi'] = 150
FICHIER_1 = "./data/data-chap6.csv" # donnees population,
FICHIER_2 = "./data/communes-20190101.json" # donnees geographiques
tableau = pd.read_csv(FICHIER_1)
carte = gpd.read_file(FICHIER_2)
tableau["CODGEO"] = tableau["CODGEO"].apply(str)
d_sup = tableau.set_index("CODGEO")[["P15_POP","prop_f"]]
carte = carte.join(d_sup,on="insee")
/Users/bussonniermatthias/miniconda3/envs/pyshs/lib/python3.8/site-packages/IPython/core/interactiveshell.py:3145: DtypeWarning: Columns (1,3,15) have mixed types.Specify dtype option on import or set low_memory=False. has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
def isint(value):
try:
int(value)
return True
except Exception:
return False
s = carte['insee'].apply(isint)
dpts = carte[s.values]['insee'].apply(lambda x:int(x[0:2]))
f_contiguous = carte[s.values][dpts < 97]
f_contiguous.head()
insee | nom | wikipedia | surf_ha | geometry | P15_POP | prop_f | |
---|---|---|---|---|---|---|---|
7 | 64026 | Anhaux | fr:Anhaux | 1235 | POLYGON ((-1.33245 43.12096, -1.33054 43.12566... | 400.0 | 49.2 |
8 | 64274 | Irouléguy | fr:Irouléguy | 943 | POLYGON ((-1.30020 43.20058, -1.29818 43.20077... | 371.0 | 49.7 |
9 | 64066 | Ascarat | fr:Ascarat | 588 | POLYGON ((-1.27637 43.20042, -1.27493 43.20230... | 317.0 | 52.2 |
10 | 64275 | Ispoure | fr:Ispoure | 785 | POLYGON ((-1.25629 43.19789, -1.25444 43.19776... | 673.0 | 50.5 |
11 | 64166 | Çaro | fr:Çaro | 402 | POLYGON ((-1.22116 43.16123, -1.21936 43.16190... | 193.0 | 47.2 |
Jettons un coup d'oeil à nos données:
f_contiguous
insee | nom | wikipedia | surf_ha | geometry | P15_POP | prop_f | |
---|---|---|---|---|---|---|---|
7 | 64026 | Anhaux | fr:Anhaux | 1235 | POLYGON ((-1.33245 43.12096, -1.33054 43.12566... | 400.0 | 49.2 |
8 | 64274 | Irouléguy | fr:Irouléguy | 943 | POLYGON ((-1.30020 43.20058, -1.29818 43.20077... | 371.0 | 49.7 |
9 | 64066 | Ascarat | fr:Ascarat | 588 | POLYGON ((-1.27637 43.20042, -1.27493 43.20230... | 317.0 | 52.2 |
10 | 64275 | Ispoure | fr:Ispoure | 785 | POLYGON ((-1.25629 43.19789, -1.25444 43.19776... | 673.0 | 50.5 |
11 | 64166 | Çaro | fr:Çaro | 402 | POLYGON ((-1.22116 43.16123, -1.21936 43.16190... | 193.0 | 47.2 |
... | ... | ... | ... | ... | ... | ... | ... |
34977 | 95219 | Ermont | fr:Ermont | 416 | POLYGON ((2.24366 48.99420, 2.24912 48.99973, ... | 28832.0 | 52.1 |
34978 | 78172 | Conflans-Sainte-Honorine | fr:Conflans-Sainte-Honorine | 988 | POLYGON ((2.07187 48.99338, 2.07147 48.99554, ... | 35019.0 | 51.3 |
34979 | 78005 | Achères | fr:Achères (Yvelines) | 972 | POLYGON ((2.04907 48.95682, 2.04918 48.96010, ... | 21053.0 | 50.8 |
34980 | 78358 | Maisons-Laffitte | fr:Maisons-Laffitte | 693 | POLYGON ((2.17312 48.96406, 2.17813 48.96383, ... | 23371.0 | 53.0 |
34981 | 95572 | Saint-Ouen-l'Aumône | fr:Saint-Ouen-l'Aumône | 1401 | POLYGON ((2.09551 49.03600, 2.09820 49.03959, ... | 24498.0 | 50.2 |
34491 rows × 7 columns
fig, ax = plt.subplots()
f_contiguous.plot(ax=ax, column='prop_f', legend=True)
<AxesSubplot:>
Remarques:
Regardons un histogram de la population
fig, ax = plt.subplots()
ax.hist(carte['prop_f'],bins=200);
fig, ax = plt.subplots()
ax.hist(carte['prop_f'], range=(45, 55), bins=501);
Regardons le ratio de genre en function de la population pour chaque communes.
fig, ax = plt.subplots()
ax.scatter(carte.P15_POP, carte.prop_f, alpha=1,s=0.1)
#ax.scatter(carte.P15_POP, np.floor(carte.P15_POP/2) / (carte.P15_POP) *100, color='C1', alpha=1,s=0.1)
#ax.scatter(carte.P15_POP, np.ceil(carte.P15_POP/2) / (carte.P15_POP) *100, color='C1', alpha=1,s=0.1)
#ax.set_ylim(20, 80)
ax.set_xscale('log')
ax.set_xlabel('Population 2015')
ax.set_ylabel('Proportion Femme')
# plt.xlim(0, 0.05)
# plt.ylim(0, 5*1e4)
Text(0, 0.5, 'Proportion Femme')
from ipywidgets import interact
known_departments = list(sorted(set(carte["insee"].apply(lambda x:x[0:2]).values)))
def _do_one(dpt, ax1, ax2):
dpt.plot( column='prop_f',legend=True,figsize=(10,5), ax=ax1)
ax2.scatter(dpt.P15_POP, dpt.prop_f, alpha=1,s=0.1)
ax2.set_xscale('log')
ax2.set_xlabel('Population 2015')
@interact(num1=known_departments, num2=known_departments)
def plot_dpt(num1='26', num2='32'):
fix, ((ax11,ax12), (ax21, ax22)) = plt.subplots(2, 2)
mon_dpt1 = carte[carte["insee"].apply(lambda x:x[0:2] == num1)]
_do_one(mon_dpt1, ax11, ax21)
mon_dpt2 = carte[carte["insee"].apply(lambda x:x[0:2] == num2)]
_do_one(mon_dpt2, ax12, ax22)
ax11.axis('off')
ax12.axis('off')
plt.grid(False)
interactive(children=(Dropdown(description='num1', index=24, options=('01', '02', '03', '04', '05', '06', '07'…
for num in known_departments:
fig, (ax1,ax2) = plt.subplots(1, 2)
dpt = carte[carte["insee"].apply(lambda x:x[0:2] == num)]
_do_one(dpt, ax1, ax2)
fig.savefig(f'dpt_{num}.png')
plt.close()
!open .