๐ BeautifulSoup - Web data 2-3
๐ฉ ์ฐพ์ ๋ฐ์ดํฐ ์์น ๊ฐ์ผ๋ก ์ง๋ ์๊ฐํ
๐ฉ ์ง๋ ์๊ฐํ import
- folium, pandas, numpy, googlemaps
๐ฉ ์๋์ ๊ฒฝ๋ ๊ฐ ์ถ๊ฐ ํด์ฃผ๊ธฐ
lat = []
lng = []
for idx, row in tqdm(df.iterrows()):
if not row["Address"] == "Multiple location":
# ๋ฐ์ดํฐ๋ฅผ ํ์ธํด๋ณด๋, Address ๋ฐ์ดํฐ์ Multiple location ๊ฐ ๋ฐ๊ฒฌ
# if ๋ฌธ์ผ๋ก ๊ฐ์ ์ ์ธํ ๊ณณ์ ํ์ธ
target_name=row["Address"] + ", " + "Chicago"
# Address ๊ฐ์ Chicago ๊ฐ์ str์ผ๋ก ํฉ์ณ์ค๋ค
gmaps_output = gmaps.geocode(target_name) # ์ฃผ์๊ฐ์ ๊ตฌ๊ธ๋งต์ ์
๋ ฅ
location_output = gmaps_output[0].get("geometry") # lat, lng ๊ฐ์ด ์๋ geometry ๊ฐ ์ถ๋ ฅ
lat.append(location_output["location"]["lat"]) # geometry ๊ฐ ๋ด๋ถ์ ์๋ lat ๊ฐ ์ถ๋ ฅ
lng.append(location_output["location"]["lng"]) # geometry ๊ฐ ๋ด๋ถ์ ์๋ lng ๊ฐ ์ถ๋ ฅ
else: # Multiple location ๊ฐ์ด๋ผ๋ฉด ์๋, ๊ฒฝ๋๋ฅผ 0์ผ๋ก append
lat.append(0)
lng.append(0)
๐ฉ googlemap ์ ์๊ฐํ ํ๊ธฐ
mapping = folium.Map(location=[41.8781136, -87.6297982], zoom_start = 11)
#๊ธฐ์ค ์๋์ ๊ฒฝ๋๋ฅผ ์ก๋๋ค
for idx, row in df.iterrows(): # df๋ฅผ iterrows ํจ์๋ก ์ธ๋ฑ์ค์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์จ๋ค
if not row["Address"] == "multiple location": # multiple location์ด ์๋ ๋
folium.Marker(
location = [row["lat"], row["lng"]], # ๊ฐ๊ฐ row ๊ฐ์ lat, lng ๊ฐ์ ๋ง์ปค๋ฅผ ์ฐ๋๋ค
popup = row["Cafe"], # ๋ง์ปค๋ฅผ ํด๋ฆญํ์ ๋, Cafe ์ด๋ฆ์ ๋์ค๊ฒ ํจ
tooltip = row["Menu"], # ๋ง์ปค์ ๋ง์ฐ์ค๋ฅผ ๊ฐ๋ค ๋์์ ๋, ๋ฉ๋ด ์ด๋ฆ์ ๋์ค๊ฒ ํจ
icon = folium.Icon(
icon = "coffee", # coffee ์์ด์ฝ์ ๋ฃ๋๋ค
prefix = "fa" # ๋์ผ
)
).add_to(mapping)
mapping
'Study_note(zb_data) > EDA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์คํฐ๋ ๋ ธํธ (BeautifulSoup + selenium) (1) | 2023.08.14 |
---|---|
์คํฐ๋ ๋ ธํธ (Slenium ํ์ ํ๊ธฐ) (0) | 2023.08.14 |
์คํฐ๋ ๋ ธํธ (BeautifulSoup Web data 2-2) (0) | 2023.08.12 |
์คํฐ๋ ๋ ธํธ (BeautifulSoup Web data 2-1) (0) | 2023.08.11 |
์คํฐ๋ ๋ ธํธ (BeautifulSoup Web data_ํ๊ธ ์น ์ฃผ์ ํ์ธํ๊ธฐ) (0) | 2023.08.11 |