import streamlit as st import pandas as pd st.set_page_config(page_title="愛媛県インフルエンザ2023") st.title("インフルエンザ") url = "https://www.pref.ehime.jp/h25115/kanjyo/topics/influ2324/index2324.html" df0 = pd.read_html( url, index_col=[0, 1], header=[0], skiprows=1, match="定点医療機関における保健所別患者報告数" )[0] df0.index = df0.index.droplevel(0) df0.columns = df0.columns.str.replace("\s", "", regex=True) df0.drop("定点数", inplace=True) df0.drop("愛媛県", axis=1, inplace=True) df0.reset_index(inplace=True) df0.rename(columns={"index": "週"}, inplace=True) df1 = ( df0.drop_duplicates(subset=["週"], keep="first") .set_index("週") .fillna(0) .astype(float) .sort_index() ) st.markdown("## 一覧") st.write(df1) with st.form("データ抽出"): city = st.selectbox("保健所を選択", df1.columns, key="city") submitted = st.form_submit_button("選択") if submitted: this_week = df1[city].iloc[-1] last_week = df1[city].iloc[-2] week_before_last = df1[city].iloc[-3] dif1 = this_week - last_week dif2 = last_week - week_before_last st.markdown("## 比較") col_left, col_right = st.columns(2) with col_left: st.metric(label="今週", value=this_week, delta=dif1) with col_right: st.metric(label="先週", value=last_week, delta=dif2) st.markdown("## グラフ") st.bar_chart(df1[city])