!pip install folium
import folium
import pandas as pd
import json
# 0~18
m = folium.Map(location=[37.546898, 127.084037], zoom_start=15)
m
#save
m.save("./folium.html")
m = folium.Map(
location=[37.546898, 127.084037],
zoom_start=15,
tiles="Stamen Toner"
)
m
m = folium.Map(
location=[37.546898, 127.084037],
zoom_start=15,
tiles="OpenStreetMap"
)
# Marker(좌표)
folium.Marker((37.546898, 127.084037)).add_to(m)
# popup
folium.Marker(
location=(37.541109, 127.079285),
popup="<b>university</b>"
).add_to(m)
#tooltip
folium.Marker(
location=(37.541109, 127.079285),
popup="<b>university</b>",
tooltip="<i>건국대</i>"
).add_to(m)
#어린이대공원 링크
folium.Marker(
location=(37.549608, 127.081852),
popup="<a href='https://www.sisul.or.kr/open_content/childrenpark/' target='_blink'>서울어린이대공원</a>",
tooltip="<i>어린이대공원</i>"
).add_to(m)
m
m = folium.Map(
location=[37.546898, 127.084037],
zoom_start=15,
tiles="OpenStreetMap"
)
#icon basic
folium.Marker(
(37.546898, 127.084037), icon=folium.Icon(color="black", icon="icon-sign")
).add_to(m)
#icon_color
folium.Marker(
location=(37.541109, 127.079285),
popup="<b>university</b>",
tooltip="<i>icon color</i>",
icon=folium.Icon(
color="red",
icon_color="pink",
icon="cloud"
)
).add_to(m)
#icon custioms
folium.Marker(
location=(37.546597, 127.075790),
popup="<b>store</b>",
tooltip="<i>icon custioms</i>",
icon = folium.Icon(
color="purple",
icon_color="white",
#prefix 변경해야 나오는 icon 존재 -> fontawesome & 보면서 하기(나오지 않는 아이콘도 존재)
icon="android",
angle=50,
prefix='fa'
)
).add_to(m)
m
m = folium.Map(
location=[37.546898, 127.084037],
zoom_start=15,
tiles="OpenStreetMap"
)
m.add_child(folium.ClickForMarker(popup="ClickForMarker"))
m = folium.Map(
location=[37.546898, 127.084037],
zoom_start=15,
tiles="OpenStreetMap"
)
m.add_child(folium.LatLngPopup())
m = folium.Map(
location=[37.546898, 127.084037],
zoom_start=15,
tiles="OpenStreetMap"
)
#Circle
folium.Circle(
location=[37.541109, 127.079285],
radius=100,
#기본이 False -> 색이 채워지지 않음
fill=True,
color="#dddddd",
fill_color="red",
popup="Circle",
tooltip="Circle tooltip"
).add_to(m)
#CircleMarker
folium.CircleMarker(
location=[37.541109, 127.079285],
radius=100,
#기본이 False -> 색이 채워지지 않음
fill=True,
color="#dddddd",
fill_color="red",
popup="CircleMarker",
tooltip="CircleMarker tooltip"
).add_to(m)
m
import json
state_data=pd.read_csv("../data/02. US_Unemployment_Oct2012.csv")
m = folium.Map([43, -102], Zoom_start=3)
folium.Choropleth(
geo_data="../data/02. us-states.json", #경계선 좌표값이 담기 데이터
data=state_data, # Series or DataFrame
columns=["State", "Unemployment"], #DataFrame columns
key_on="feature.id",
fill_color="BuPu",
fill_opacity=1,
line_opacity=1,
lengend_name="Unemployment rate(%)"
).add_to(m)
m
import pandas as pd
df = pd.read_csv("../data/02. 서울특별시 동작구_주택유형별 위치 정보 및 세대수 현황_20210825.csv", encoding="euc-kr")
#데이터 전처리
df= df.dropna()
df.info()
df.reset_index(drop=True)
df.columns
df = df.rename(columns={"연번 ":"연번", "분류 ":"분류"})
del df["연번"]
df.tail(2)
df.describe()
# folium
m = folium.Map(location=[37.491526, 126.916653], zoom_start=13)
for idx, row in df.iterrows():
#location
lat, lng = row.위도, row.경도
#Marker
folium.Marker(
location=[lat, lng],
popup=row.주소,
tooltip=row.분류,
icon=folium.Icon(
icon="home",
#199 -> 50%
color= "lightred" if row.세대수 >= 199 else "lightblue",
icon_color="darkred" if row.세대수 >= 199 else "darkblue")
).add_to(m)
#Cricle
folium.Circle(
location = [lat, lng],
radius=row.세대수 * 0.5,
fill=True,
color="pink" if row.세대수 >= 518 else "green",
fill_color="pink" if row.세대수 >= 518 else "green"
).add_to(m)
m
Reference
1) 제로베이스 데이터스쿨 강의자료
2) 문자열 인코딩 참고: https://onlywis.tistory.com/2
3) folium reference: https://nbviewer.org/github/python-visualization/folium/tree/main/examples/