!pip install lxml
!pip install seaborn
!apt install fonts-ipafont-gothic
!rm /content/.cache/matplotlib/fontList.json
import pandas as pd
url = 'https://ehimesvc.jp/?p=70'
dfs = pd.read_html(url, index_col=0, na_values=['活動中止', '終了', '休止'])
df = dfs[0]
df.dropna(how='all', inplace=True)
df.drop('合計', inplace=True)
df['日付'] = pd.to_datetime(df.index, format='%m月%d日')
df['日付'] = df['日付'].apply(lambda x: x.replace(year=2018))
df.set_index('日付', inplace=True)
df.fillna(0, inplace=True)
df
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns
import datetime
sns.set(font=['IPAPGothic'], style='whitegrid')
df2 = df.tail(7)
df2.plot.bar(stacked=True, rot=45, title='愛媛県ボランティア数動向 直近の1週間')
df2
df_w = df.resample('W').sum()
df_w.plot(title='愛媛県ボランティア数動向')
df_w
df3 = df.tail(2).T
df3.columns = ['昨日', '今日']
df3
df_pre_day = df.diff().fillna(0)
df3_d = df_pre_day.tail(1).T
df3_d.columns = ['前日比']
df3_d
df_pre_week = df.diff(7).fillna(0)
df3_w = df_pre_week.tail(1).T
df3_w.columns = ['前週比']
df3_w
df3 = df3.join(df3_d)
df3 = df3.join(df3_w)
df3
df.plot(figsize=(10, 5))
df.plot.bar(figsize=(10, 5), stacked=True)
df_pre_day.plot.bar()
df_pre_week.plot.bar()