본문 바로가기

python

pandas matplotlib folium

파이썬은 공부할수록 많이 유용한 도구임을 알게된다.

오늘 배운 여러 도형만들기 사례를 나중에 보기 위하여 기록한다.

import folium
import pandas as pd

seoul_map = folium.Map(location=[37.55, 126.98], zoom_start=12)
seoul_map.save('/Users/yangdaeyeong/Downloads/5674-833_4th/seoul.html')

seoul_map2 = folium.Map(location=[37.55, 126.98], zoom_start=12, tiles='Stamen Terrain')
seoul_map3 = folium.Map(location=[37.55, 126.98], zoom_start=15, tiles='Stamen Toner')
seoul_map2.save('/Users/yangdaeyeong/Downloads/5674-833_4th/seoul2.html')
seoul_map3.save('/Users/yangdaeyeong/Downloads/5674-833_4th/seoul3.html')
import folium
import pandas as pd
import json

file_path = 'part4/경기도인구데이터.xlsx'
df = pd.read_excel(file_path, index_col='구분')
df.columns = df.columns.map(str)

geo_path = 'part4/경기도행정구역경계.json'
try:
    geo_data = json.load(open(geo_path, encoding='utf-8'))
except:
    geo_data = json.load(open(geo_path, encoding='utf-8-sig'))

g_map = folium.Map(location=[37.5502, 126.982], tiles='Stamen Terrain', zoom_start=9)

year = '2017'
folium.Choropleth(geo_data,
                  data=df[year],
                  columns=[df.index, df[year]],
                  fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.3,
                  threshold_scale=[10000, 100000, 300000, 500000, 700000],
                  key_on='feature.properties.name').add_to(g_map)
g_map.save('./g population'+year+'.html')

'python' 카테고리의 다른 글

시계열 데이터  (0) 2022.02.22
pandas index  (0) 2022.02.22
numpy histogram  (0) 2022.02.21
누락 데이터 치환  (0) 2022.02.20
누락데이터 처리  (0) 2022.02.20