from tqdm import tqdm, trange
import time
blist = yd4326['EMD_NM'].unique().tolist()
yd4326['EMD_NM'].unique()
select_loc = pd.DataFrame(columns=['id', 'x', 'y', 'total', '행정동', 'etl_ymd', 'geometry', '법정동'])
for i in tqdm(blist, desc='tqdm description'):
target_loc = yd4326.loc[yd4326['EMD_NM']==i,'geometry'].iloc[0]
select_pt = gdf_pop_4326[gdf_pop_4326.within(target_loc)]
select_pt['법정동'] = i
select_loc = select_loc.append(select_pt, ignore_index=True)
display(select_loc.head(1),select_loc.shape)
id x y total 행정동 etl_ymd geometry 법정동
0 48838947 302502 549393 2.29 당산제2동 2020-07-01 POINT (126.89451 37.54160) 당산동
(5568146, 8)
print(select_loc['법정동'].nunique(), ',' ,yd4326['EMD_NM'].nunique())
34 , 34
법정동별 생활인구 전체기간 평균 ˙ 총합
t_mean = select_loc.groupby('법정동')[['total']].mean().reset_index()
t_mean.rename(columns={'법정동':'EMD_NM'}, inplace=True)
t_sum = select_loc.groupby('법정동')[['total']].sum().reset_index()
t_sum.rename(columns={'법정동':'EMD_NM'}, inplace=True)
pop_mean = yd4326.merge(t_mean, on='EMD_NM')
pop_sum = yd4326.merge(t_sum, on='EMD_NM')
pop_mean3857 = pop_mean.to_crs(epsg=3857)
pop_sum3857 = pop_sum.to_crs(epsg=3857)
plot
ax = pop_sum3857.plot("total", figsize=(25, 25),alpha=0.75,cmap="Blues",edgecolor='k', legend=True)
cx.add_basemap(ax, source=cx.providers.OpenStreetMap.Mapnik)
ax = pop_mean3857.plot("total", figsize=(25, 25),alpha=0.75,cmap="Blues",edgecolor='k', legend=True)
cx.add_basemap(ax, source=cx.providers.CartoDB.Voyager)