-
Notifications
You must be signed in to change notification settings - Fork 0
/
od.py
56 lines (43 loc) · 1.57 KB
/
od.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
import sqlite3
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm
def get_data_from_bdd(txt):
conn = sqlite3.connect(txt)
cur = conn.cursor()
dfflows=pd.read_sql_query("SELECT * FROM TU_GEO_LPW_MATRIX", conn)
conn.close()
return dfflows
#url='/Users/ismailsaadi/FNRS_research/uMOB/BELGIUM/ss/sh_statbel_statistical_sectors_20190101.shp'
#maps2=gpd.read_file(url)
df=get_data_from_bdd('data/TU_GEO_LPW_SECTOR.sqlite')
df['CD_REFINS_RESIDENCE']=[k.split('_')[1][:5] for k in df.CD_SECTOR_RESIDENCE]
df['CD_SECTOR_RESIDENCE_0']=[k.split('_')[1] for k in df.CD_SECTOR_RESIDENCE]
df['CD_SECTOR_RESIDENCE_PR']=[k.split('_')[1][0] for k in df.CD_SECTOR_RESIDENCE]
test=[]
for k in df.CD_SECTOR_WORK:
if k=='FOR':
test.append('FOR')
else:
test.append(k.split('_')[1][:5])
df['CD_REFINS_WORK']=test
test=[]
for k in df.CD_SECTOR_WORK:
if k=='FOR':
test.append('FOR')
else:
test.append(k.split('_')[1])
df['CD_SECTOR_WORK_0']=test
test=[]
for k in df.CD_SECTOR_WORK:
if k=='FOR':
test.append('FOR')
else:
test.append(k.split('_')[1][0])
df['CD_SECTOR_WORK_PR']=test
df['OBS_VALUE_NUM']=[int(k.split(',')[0]) for k in df['OBS_VALUE']]
#df_cp=df[['CD_SECTOR_WORK_0','OBS_VALUE_NUM']].groupby(['CD_SECTOR_WORK_0']).sum()
plt.imshow(pd.crosstab(index=df.CD_REFINS_RESIDENCE,columns=df.CD_REFINS_WORK, values=df.OBS_VALUE_NUM, aggfunc='sum').values, origin='lower', norm=LogNorm(vmin=0.01), cmap='OrRd')
plt.show()