유동인구 시각화

SOOYEON·2022년 9월 4일
0

geopandas

목록 보기
1/3
post-custom-banner
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)] # 법정동 안에 위치한 격자인구 데이터 boolean
    select_pt['법정동'] = i
    select_loc = select_loc.append(select_pt, ignore_index=True)

display(select_loc.head(1),select_loc.shape)

# output

    id	        x	    y	    total	행정동	    etl_ymd	    geometry	                법정동
0	48838947	302502	549393	2.29	당산제22020-07-01	POINT (126.89451 37.54160)	당산동

(5568146, 8)


print(select_loc['법정동'].nunique(), ',' ,yd4326['EMD_NM'].nunique())

# output
34 , 34

법정동별 생활인구 전체기간 평균 ˙ 총합

# mean
t_mean = select_loc.groupby('법정동')[['total']].mean().reset_index()
t_mean.rename(columns={'법정동':'EMD_NM'}, inplace=True)

# sum
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')

# 좌표계 변환 3857
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) # , zoom=15)
#cx.add_basemap(ax, source=cx.providers.Stamen.TonerLabels)

# plot
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) # , zoom=15)
#cx.add_basemap(ax, source=cx.providers.Stamen.TonerLabels)

post-custom-banner

0개의 댓글