Spaces:
Build error
Build error
| import streamlit as st | |
| import pandas as pd | |
| import datetime | |
| import create_object as co | |
| import duckdb | |
| df = pd.read_csv("data/online_retail.csv") | |
| # データ型整備:ID項目のSTRING化など | |
| df = df.astype({'CustomerID': 'object'}) | |
| df = df[df["UnitPrice"] * df["Quantity"] > 0] | |
| country_list = df["Country"].unique() | |
| st.set_page_config( | |
| page_title="購買データ分析App", | |
| layout="wide", | |
| ) | |
| def main(): | |
| st.title("購買データ分析App") | |
| with st.sidebar.form(key="my_form"): | |
| analysis_menu = st.selectbox("分析メニュー", co.analysis_menu_list) | |
| country = st.multiselect("国を選択してください。", country_list) | |
| if len(country) != 0: | |
| country = "','".join(country) | |
| country = f"Country in ('{country}')" | |
| else: | |
| country = "True" | |
| st.write("2010年の日付を入れてください。") | |
| start_date = st.date_input("開始日", datetime.date(2010, 1, 1)) | |
| end_date = st.date_input("終了日", datetime.date(2010, 12, 31)) | |
| submit_button = st.form_submit_button(label = "分析開始") | |
| if submit_button: | |
| # 処理を実行 | |
| sql = co.create_sql(analysis_menu, country, start_date, end_date) | |
| df_output = duckdb.query(sql).to_df() | |
| try: | |
| fig = co.create_graph(analysis_menu, df_output) | |
| st.plotly_chart(fig) | |
| except: | |
| print("グラフ無し") | |
| st.table(df_output.head(100)) | |
| st.write("上位100行まで、全体を見たい場合はCSVでダウンロードしてください。") | |
| st.download_button( | |
| "Press to Download", | |
| df_output.to_csv(index=False).encode('utf-8'), | |
| "file.csv", | |
| "text/csv", | |
| key='download-csv' | |
| ) | |
| if __name__ == '__main__': | |
| main() |