RUBY
[WebData][chicago] 6. 시카고 맛집 데이터 지도 시각화 본문
웹 데이터 수집하고 정리하기
시카고 맛집 데이터 분석
6. 시카고 맛집 데이터 지도 시각화
1. 불러오자
import folium
import pandas as pd
import numpy as np
import googlemaps
from tqdm import tqdm
df = pd.read_csv("../data/03. best_sandwiches_list_chicago2.csv", index_col=0)
df.tail(10)
2.
gmaps_key = "전에 발급받은 geocoding api key 넣기"
gmaps = googlemaps.Client(key=gmaps_key)
lat = []
lng = []
for idx, row in tqdm(df.iterrows()):
if not row["Address"] == "Multiple location":
target_name = row["Address"] + ", " + "Chicago"
# print(target_name)
gmaps_output = gmaps.geocode(target_name)
location_ouput = gmaps_output[0].get("geometry")
lat.append(location_ouput["location"]["lat"])
lng.append(location_ouput["location"]["lng"])
# location_output = gmaps_output[0]
else:
lat.append(np.nan)
lng.append(np.nan)
3. 좌표 넣어주기~
len(lat), len(lng)
df.tail()
df["lat"] = lat
df["lng"] = lng
df.tail()
4. 매핑 성공~
mapping = folium.Map(location=[41.8781136, -87.6297982], zoom_start=11)
for idx, row in df.iterrows():
if not row["Address"] == "Multiple location":
folium.Marker(
location=[row["lat"], row["lng"]],
popup=row["Cafe"],
tooltip=row["Menu"],
icon=folium.Icon(
icon="coffee",
prefix="fa"
)
).add_to(mapping)
mapping
'데이터 분석 > EDA_웹크롤링_파이썬프로그래밍' 카테고리의 다른 글
[WebData][Movie] 2. 자동화를 위한 코드 (0) | 2023.02.05 |
---|---|
[WebData][Movie] 1. 네이버 영화 평점 사이트 분석 (0) | 2023.02.05 |
[WebData][chicago] 5. Regular Expression (1) | 2023.02.05 |
[WebData][chicago] 4. 하위페이지 분석 (0) | 2023.02.05 |
[WebData][chicago] 3. 50개 가게에 대해 정보 추출 (0) | 2023.02.05 |
Comments