import streamlit as st import pandas as pd import matplotlib.pyplot as plt import pandas_bokeh import seaborn as sns from pytrends.request import TrendReq import time import random # 글 쓰기(링크 삽입) st.title('VIETNAM DONGDAEMUN FOOOOOOOOOD!!!!!!!!!') st.header('Selection of Vietnamese Restaurants in Dongdaemun Area') st.subheader('Variety of dishes from different region in Vietnam, made affordable and delicious for local taste') st.subheader('Items such as Pho Soup, Bun Bo Hue, Cha Gio or Com Chien') st.write('''Write something here about the booming of Vietnamese Restaurant in Korea - particularly the fast growing food scene in Dongdaemun [푸드트럭](https://namu.wiki/w/%EB%B2%A0%ED%8A%B8%EB%82%A8%20%EC%9A%94%EB%A6%AC) .''' ) # 사진 삽입 st.image('final_image_2.jpg', caption='A Spread of Vietnamese Dishes You Might Be Able To Find') st.image('final_image_4.jpg', caption='A popular choice everywhere: Vietnamese Pho Soup') st.image('final_image_3.jpg', caption='Hidden Gem: Banh Xeo') st.header('Cheap and Delicious: One can find a variety of Vietnamese Restaurant in Dongdaemun Area') st.subheader('Hosting dishes from North to South Vietnam') st.subheader('The almost infinite choices will leave you looking for reviews!') st.write('''Before deciding on which dish you'd want ~ carefully browse through the Blog section for an intimate look at the local food joints''' ) # 데이터 보여주기 df_동대문구_베트남_맛집 = pd.read_excel('vietnam_food_dongdaemun_BLOGS.xlsx', index_col=0) st.write('We have narrowed down to 150 most relevant blogs!!',df_동대문구_베트남_맛집) df_동대문구_베트남_맛집_keyword = pd.read_excel('vietnam_food_KEYWORDS.xlsx', index_col=0) st.write('블로그 글에서 가장 많이 출현한 단어는 ~~~ 설명~~~', df_동대문구_베트남_맛집_keyword) # 워드클라우드 - WORDCLOUD st.write('주요 단어들을 워드클라우드로 보여주면 다음과 같다') st.image('final_WORDCLOUD.png') # 연결망 분석 - NETWORK st.write('''취재팀은 주요 단어들 간에 공동출현하는 관계를 바탕으로 의미연결망을 그려보았다. 분석결과, ~~설명~~''') st.image('final_NETWORK.png') #### The Section Below Is Extra Stuff We Gotta Think About # df_동대문구_베트남_맛집_2 = pd.read_excel('vietnam_food_dongdaemun_BLOGS.xlsx', index_col=0) st.write('Again, the list of blog posts on Dongdaemun Vietnamese Restaurant', df_동대문구_베트남_맛집_2) # 검색어 입력 받아 출력 query = st.text_input('Enter Keyword such as: food name, restaurant name', key='region1_input') df_동대문구_베트남_맛집_2['select1']=df_동대문구_베트남_맛집_2['text'].apply(lambda x: 1 if query in x else 0) st.write('검색 결과:', df_동대문구_베트남_맛집_2[df_동대문구_베트남_맛집_2['select1']==1]) ##### HEATMAP ##### # List of user-agents to rotate USER_AGENTS = [ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Firefox/91.0', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0' ] def fetch_trends_data(kw_list, timeframe, geo): pytrends = TrendReq(hl='en-US', tz=360) pytrends.build_payload(kw_list, timeframe=timeframe, geo=geo) df_trends = pytrends.interest_over_time() # Introduce random delays to avoid being blocked time.sleep(random.uniform(1, 5)) # Rotate user-agents user_agent = random.choice(USER_AGENTS) pytrends = TrendReq(hl='en-US', tz=360, custom_useragent=user_agent) pytrends.build_payload(kw_list, timeframe=timeframe, geo=geo) df_trends = pytrends.interest_over_time() return df_trends # Fetch data for the year 2023 kw_list = ['베트남 음식'] timeframe = '2023-01-01 2023-12-31' geo = 'KR' df_trends = fetch_trends_data(kw_list, timeframe, geo) # Streamlit app st.title('Monthly Google Trends Data for Vietnamese Food in Seoul (2023)') if not df_trends.empty: df_trends = df_trends.drop(columns=['isPartial']) df_trends.reset_index(inplace=True) # Extract month from date df_trends['month'] = df_trends['date'].dt.to_period('M') monthly_counts = df_trends.groupby('month')[kw_list].sum().reset_index() # Display the data st.write('Number of searches for each month:') st.write(monthly_counts) # Create the heatmap plt.figure(figsize=(10, 6)) monthly_counts_pivot = monthly_counts.pivot_table(index='month', values=kw_list) sns.heatmap(monthly_counts_pivot.T, annot=True, fmt="d", cmap='YlGnBu', cbar=False) st.pyplot(plt) else: st.write("No data received from Google Trends.") # 교통사고 유형과 연도에 따른 pivot table 보여주기 #df_교통사고_pivot=df_교통사고.pivot_table(index='사고유형구분', columns='사고연도', values='사고건수', aggfunc='sum') #df_교통사고_heatmap=df_교통사고_pivot.style.background_gradient(cmap='Oranges').format("{:.2f}") #st.write('다음 표는 교통사고 건수를 유형과 연도에 따라 구분한 것이다', df_교통사고_heatmap) # 검색어 입력 받아 pivot table 출력 #query_pivot = st.text_input('이 곳에 지역명(시군구)을 입력하면 관련 데이터만 검색해 보여줍니다', key='region2_input') #df_교통사고['select2']=df_교통사고['사고지역위치명'].apply(lambda x: 1 if query_pivot in x else 0) #df_교통사고_pivot_selected=df_교통사고[df_교통사고['select2']==1].pivot_table(index='사고유형구분', columns='사고연도', values='사고건수', aggfunc='sum') #df_교통사고_heatmap_selected=df_교통사고_pivot_selected.style.background_gradient(cmap='Oranges').format("{:.2f}") #st.write('검색 결과:', df_교통사고_heatmap_selected) # pandas_bokeh 그래프 보여주기 #st.write('전국 교통사고 데이터에 따르면, 사고건수와 중상자수는 밀접한 관련을 맺고 있다. ~~~설명~~. *그래프 내 점에 커서를 대면 지역명이 나타난다') #p_scatter = df_교통사고.plot_bokeh.scatter( # x="사고건수", # y="중상자수", # title="사고건수와 중상자수", # size=10, # hovertool_string="""
위치:@{사고지역위치명}
""" #) #st.bokeh_chart(p_scatter, use_container_width=True) # 선택한 조건에 따라 출력 #option = st.selectbox('연도를 선택하면 해당 시기의 그래프를 보여줍니다', # (2012, 2013, 2014, 2015, 2016, 2018, 2017, 2019, 2020, 2021), key='year_input') #p_scatter_selected = df_교통사고[df_교통사고['사고연도']==option].plot_bokeh.scatter( # x="사고건수", # y="중상자수", # title="사고건수와 중상자수", # size=10, # hovertool_string="""
위치:@{사고지역위치명}
""" #) #st.write('검색 결과:') #st.bokeh_chart(p_scatter_selected, use_container_width=True)