Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotoripiyopiyo/145bf40b9efe596ea2c0da34ec252573 to your computer and use it in GitHub Desktop.
Save kotoripiyopiyo/145bf40b9efe596ea2c0da34ec252573 to your computer and use it in GitHub Desktop.
とうとうPythonで「新型コロナの曜日別の年代ごと陽性者数」を出すことに成功
###ライブラリ読み込み
import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import japanize_matplotlib
###csv読み込む
covid_data = pd.read_csv("(都合によりURLのあちこちにスペース入ってるけど、使う時はスペース除いてください)https:// stopcovid19. metro. tokyo. lg. jp/ data/ 130001_tokyo_covid19_patients. csv", index_col="公表_年月日", parse_dates=True)
###曜日と患者_年代のピボットテーブルにする
covid_pivot = pd.pivot_table(covid_data, index="患者_年代", columns="曜日", values="都道府県名", aggfunc="count")
###行と列を並び替える
covid_pivot_alignment = covid_pivot.reindex(index=["10歳未満","10代","20代","30代","40代","50代","60代","70代","80代","90代","100歳以上","不明","-"], columns=["月","火","水","木","金","土","日"])
###NaNを0で埋める
covid_pivot_alignment_fill = covid_pivot_alignment.fillna(0)
###不明と-を足して年齢不明にし、不要な行や桁を削除
covid_pivot_alignment_fill.loc["年齢不明"] = covid_pivot_alignment_fill.loc["不明"] + covid_pivot_alignment_fill.loc["-"]
covid_pivot_fix = covid_pivot_alignment_fill.drop(["不明", "-"]).round().astype(int)
###グラフ描画
plt.figure(figsize=(20,20))
plt.rcParams["font.size"] = 18
print("曜日別の年代ごとcovid19陽性者数")
for i in range(len(covid_pivot_fix)):
plt.subplot(4, 3, i+1)
plt.title(covid_pivot_fix.index[i])
plt.plot(covid_pivot_fix.iloc[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment