-
국내 메이저 영화관 브랜드(CJCGV, 메가박스, 롯데시네마) 데이터 분석Data Analysis/LifeStyles 2021. 4. 5. 00:48
국내 메이저 극장 브랜드(CJCGV, 메가박스, 롯데시네마) 위치 데이터를 가져와서 지도에 시각화해보도록 하겠다. 데이터는 카카오 지도 API에서 가져오도록 하겠다.
0. 데이터 가져오기 & 전처리
아래 코드가 문제없이 돌아간다면 전국 영화관 위치 데이터를 확인할 수 있을 것이다.
import pandas as pd import requests from bs4 import BeautifulSoup as bs link='https://inasie.github.io/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D/5/' gu=pd.read_html(link,encoding='utf-8')[0] gu['법정동코드']=gu['법정동코드'].astype(str) sido=gu[(gu['법정동코드'].str.contains('000')) | (gu['법정동주소']=='세종특별자치시') ] api='~~' theater=['롯데시네마','메가박스','CGV'] data=[] for a in sido['법정동주소']: for q in theater: for i in range(1,46): query = a + q url = f'''https://dapi.kakao.com/v2/local/search/keyword?query={query}&page={i}&size=15''' headers = { "Authorization": f"KakaoAK {api}" } places = requests.get(url, headers = headers).json()['documents'] data.extend(places) df=pd.DataFrame(data) df=df.drop_duplicates('place_name',keep='first') df2=df[df['category_group_name'].str.contains('문화')] df2['name']=df2['category_name'].apply(lambda x:x.split(' ')[-1]) df2=df2[df2['name']!='영화관']
1. 브랜드별 영화관 수
국내 영화관은 CJCGV, 롯데시네마, 메가박스 순으로 많은 상황이다.
실제 홈페이지에 있는 데이터와 다른 점이 있는데 카카오에서 제공해주고 있는 데이터에는 앞으로 오픈할 예정인 영화관도 포함되어 있기 때문이다.
import seaborn as sns import matplotlib.pyplot as plt from IPython.display import set_matplotlib_formats total=pd.DataFrame(df2.groupby(['name']).count()['place_name']) set_matplotlib_formats("retina") plt.style.use('ggplot') plt.rcParams["font.family"] = 'Malgun Gothic' fig, ax = plt.subplots(1,1, figsize=(20, 9)) plt.rcParams["font.size"] = 12 ax.bar(total.index, total['place_name'], width=0.55, edgecolor='darkgray', color=sns.color_palette("crest", 7), linewidth=0.7) ax.set_xticklabels(total.index, fontsize =16) ax.set_title('브랜드별 영화관 수') for x,y in enumerate(list(total['place_name'])): ax.annotate(f"{y}", xy=(x, y+5), va = 'center', ha='center',fontweight='light', fontfamily='serif',fontsize=15, color='#4a4a4a')
2. 브랜드별 영화관 수 지도 시각화
전국 영화관 위치 데이터를 다음과 같이 지도에 시각화해보도록 하겠다. 아래 코드를 통해 브랜드별 색깔을 다르게 지정하였다. 또한 마우스를 해당 위치에 호버링하면 주소와 이름을 확인할 수 있다.
from mapboxgl.utils import * from mapboxgl.viz import * from mapboxgl.utils import df_to_geojson import json df2['x']=df2['x'].astype(float) df2['y']=df2['y'].astype(float) geo_data = df_to_geojson( df=df2, properties=['place_name', 'place_url','address_name','phone','name'], lat='y', lon='x', precision=5, filename = "theaters.geojson" ) geo_data_2 = 'theaters.geojson' with open(geo_data_2) as f: gdata = json.loads(f.read()) token = '~~' center = [126.984630, 37.520189] match_color_stops = [ ['롯데시네마', 'rgb(46,204,113)'], ['메가박스', 'rgb(231,76,60)'], ['CJCGV', 'rgb(142,68,173)'] ] viz = CircleViz( data=gdata, access_token=token, color_function_type='match', color_property='name', color_stops=match_color_stops, center=center, zoom=10, radius=3.5, ) viz.show() viz.create_html('movies.html')
마지막으로 영화관 수 기준으로 클러스터링을 해보도록 하겠다.
color_stops = create_color_stops([10,20,30,40,50], colors='BrBG') cviz = ClusteredCircleViz(gdata, access_token=token, color_stops=color_stops, radius_stops=[[1,5], [10, 10], [50, 15], [100, 20]], radius_default=2, cluster_maxzoom=10, cluster_radius=30, label_size=12, opacity=0.9, center=center, zoom=6) cviz.show() cviz.create_html('movies number.html')
'Data Analysis > LifeStyles' 카테고리의 다른 글
제주도 렌터카 업체 정보 분석 & 시각화 With Python & Mapbox (0) 2021.06.07 서울 크로스핏 박스 지도 시각화 with Python, Mapbox, 카카오 API (0) 2021.05.31 NBA Data Analysis - Top 10 포인트 가드의 어시스트/턴오버 분석 (0) 2021.05.19 국내 SPA 패션 브랜드 매장 수 비교 분석(ZARA, 8Seconds, SPAO, Etc) (1) 2021.04.06 서울시 프랜차이즈 햄버거(버거킹/맥도날드/맘스터치/롯데리아) 분석 & 시각화 with Python, Pydeck (0) 2021.03.06