Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Archives
Today
Total
관리 메뉴

RUBY

[WebData][chicago] 6. 시카고 맛집 데이터 지도 시각화 본문

데이터 분석/EDA_웹크롤링_파이썬프로그래밍

[WebData][chicago] 6. 시카고 맛집 데이터 지도 시각화

ruby-jieun 2023. 2. 5. 21:48

 

 

 

 

웹 데이터 수집하고 정리하기
시카고 맛집 데이터 분석
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
Comments