トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

PRG-PY-corona

 兵庫県のエクセルファイルから発症日のリストを抽出する

PRG-PY-pandasで書いてみる

https://qiita.com/MuAuan/items/88d5d0c416abb9e9915e

Roを求める::PRG-PY-sir

コード データをプロット

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_excel('corona-kanjajokyou(1).xlsx')

dt = df[['発症日','発表日','年代','性別']]

print('dataframeの行数・列数の確認==>\n', dt.shape)
print('indexの確認==>\n', dt.index)
print('columnの確認==>\n', dt.columns)
print('dataframeの各列のデータ型を確認==>\n', dt.dtypes)
# 発症日の抽出
dh = pd.DataFrame(dt['発症日'].value_counts())
dh2 = dh[dh.index != '症状なし']
dh2 = dh2[dh2.index != '調査中']
dh2.index=pd.to_datetime(dh2.index,format='%Y-%m-%d')
# 発表日の抽出
dh3 = pd.DataFrame(dt['発表日'].value_counts())
dh3.index=pd.to_datetime(dh3.index,format='%Y-%m-%d')
# 男女別の抽出
dh4m = pd.DataFrame( ds.groupby(['発症日'])['性別_男性'].sum() )
dh4m = dh4m[dh4m.index != '調査中']
dh4m = dh4m[dh4m.index != '症状なし']
dh4m.index=pd.to_datetime(dh4m.index,format='%Y-%m-%d')
dh4f = ds.groupby(['発症日'])['性別_女性'].sum() 
dh4f = dh4f[dh4f.index != '調査中']
dh4f = dh4f[dh4f.index != '症状なし']
dh4f.index=pd.to_datetime(dh4f.index,format='%Y-%m-%d')
# 発症日不明の抽出
ck_date =['症状なし','調査中']
dh5 = ds.query('発症日 in @ck_date' )
dh5e = pd.DataFrame(dh5['発表日'].value_counts())
dh5e.rename(columns={'発表日': '不明'}, inplace=True)
# 年代べつの抽出
dh6 =pd.get_dummies(dt[['年代']], columns=['年代'])
dh6s = dh6.sum()


dd =pd.concat([dh3,dh2.reindex(dh3.index)],axis=1)

print(dd.sort_index())

dd.plot()
plt.show()

結果

            発表日   発症日
2020-03-01    1   4.0
2020-03-03    2   4.0
2020-03-05    1   3.0
2020-03-06    4   6.0
2020-03-07    2   5.0
2020-03-08    2   6.0
2020-03-09    4   5.0
2020-03-10    9   8.0
2020-03-11   12   9.0
2020-03-12    9   3.0
2020-03-13   10   2.0
2020-03-14   11   4.0
2020-03-15   11   NaN
2020-03-16    4   NaN
2020-03-17    4   3.0
2020-03-18    5   6.0
2020-03-19    2   7.0
2020-03-20    8   2.0
2020-03-21    6   6.0
2020-03-22    4   1.0
2020-03-23    2   7.0
2020-03-24    5   4.0
2020-03-25    1   5.0
2020-03-26    1  12.0
2020-03-27    3  13.0
2020-03-28    3  11.0
2020-03-29    7  13.0
2020-03-30    4  13.0
2020-03-31   11  11.0
2020-04-01   14  10.0
2020-04-02    7   6.0
2020-04-03    6   5.0