コロナデータ3(曜日ごとの周期性)
やりたいこと
感染者数、死者数、検査数の3つについて、曜日ごとの周期性があるのかを検証。
予想は、感染者数と検査数は周期性あり(土日は検査数が少なくなる → 感染者数も少なくなる)
死者数は周期性なし。(土日だから死なないとか報告しないとかはないのでは。)
使用データ
sum_per_weekday = data_eight_w.mean(level = 'weekday')
sum_per_weekday
コード
全8か国合計
感染者数、死者数、検査数どれもやっていることは基本的に同じなので、関数にした。
def make_bar_plot(df:pd.DataFrame, target: 'str'): sns.set() fig = plt.figure() ax0 = fig.add_subplot(111, title = target) sns.barplot(x = 'weekday',\ y = target,\ data = df.reset_index(),\ ax = ax0) ax0.tick_params(axis='x', rotation=315) fig.savefig('output/' + target + '.png') return make_bar_plot(mean_per_weekday, 'new_cases') make_bar_plot(mean_per_weekday, 'new_deaths') make_bar_plot(mean_per_weekday, 'new_tests')
- 感染者数
- 死者数
- 検査数
よくわからん。笑
国単位
日本
def make_bar_plot(df:pd.DataFrame, target: 'str', country: 'str'): sns.set() fig = plt.figure() ax0 = fig.add_subplot(111, title = country + '_' + target) sns.barplot(x = 'weekday',\ y = target,\ data = df.reset_index(),\ ax = ax0) ax0.tick_params(axis='x', rotation=315) fig.savefig('output/' + country + target + '.png') return def weekday_mean(df: pd.DataFrame, target: 'str'): country_df = df.loc[(slice(None), target), :] country_df = country_df.reset_index(level = 'location', drop = True) country_df_w = country_df.set_index([country_df.index.day_name(), country_df.index]) country_df_w.index.names = ['weekday', 'date'] weekday_mean = country_df_w.mean(level = 'weekday') return weekday_mean target = 'Japan' data_jpn = weekday_mean(data, target) make_bar_plot(data_jpn, 'new_cases', target) make_bar_plot(data_jpn, 'new_deaths', target) make_bar_plot(data_jpn, 'new_tests', target)
- 感染者数
- 死者数
- 検査数
アメリカ
- 感染者数
- 死者数
- 検査数
中国
- 感染者数
- 死者数
- 検査数
フランス
- 感染者数
- 死者数
- 検査数
ブラジル
- 感染者数
- 死者数
- 検査数
インド
- 感染者数
- 死者数
- 検査数
ブラジルと中国の検査数は?
どっちもすべてNaNでは?
check0 = data.loc[(slice(None), 'China'), 'new_tests'].isnull().all() check1 = data.loc[(slice(None), 'Brazil'), 'new_tests'].isnull().all() print(check0) print(check1)
True True
全部NaNだった
まとめ
検査数について、曜日ごとの偏りをみると、日本やフランスなどでは特に偏りがあった。
なので、統一して7日間の移動平均を用いて感染者数などは見たほうがよいかなと。