<jupyter_start><jupyter_text>都道府県別の感染者数の統計 2020年10月10日時点のデータ<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
!pip install  japanize_matplotlib 
!pip install japanmap
import japanize_matplotlib 
import seaborn as sns
import japanmap as jm
!wget https://raw.githubusercontent.com/UTDataMining/2020A/master/week3/population.csv
!wget https://raw.githubusercontent.com/UTDataMining/2020A/master/week3/patients.csv
df1 = pd.read_csv('population.csv', encoding='utf-8')
df2 = pd.read_csv('patients.csv', encoding='utf-8')
covid = pd.merge(df1, df2, on='Prefecture')
covid.head(10)
# 都道府県別10万人あたりの感染者数
covid['Rate'] = covid['Cases']*100000/covid['Population']
covid.sort_values('Rate', ascending=False).head(10)
# 棒グラフ
covid.plot.bar(x='Prefecture', y=['Rate'], figsize=(10,5));
# ヒストグラム
covid['Rate'].hist(bins=10);
# 記述統計
covid['Rate'].describe()
#平均値, 中央値, 偏差, 最小, 最大
print(covid['Rate'].mean(),covid['Rate'].median(), covid['Rate'].std(), covid['Rate'].min(), covid['Rate'].max())
# 箱ヒゲ図
covid['Rate'].plot.box();
# 歪度と尖度
print(covid['Rate'].skew(), covid['Rate'].kurt())
# 分布のカーネル密度推定
covid['Rate'].plot.kde();
# ヒストグラムと分布
covid["Rate"].plot(kind="hist", bins=10)
covid["Rate"].plot(kind="kde", secondary_y=True);
# ヒストグラムと分布
sns.distplot(covid['Rate'], bins=10);
# 相関係数
covid.corr()
# ヒートマップ
sns.heatmap(data=covid.corr());
# 散布図
covid.plot.scatter(x='Population', y='Rate');
# 散布図
sns.jointplot(x='Population', y='Rate', data=covid);
# カーネル密度推定
sns.jointplot(x='Population', y='Rate', data=covid, kind='kde');
# 散布図
sns.pairplot(data=covid);
# 回帰直線
sns.regplot(x='Population', y='Rate', data=covid);
# 回帰曲線（2次の多項式）
sns.regplot(x='Population', y='Rate', data=covid, order=2);
# 都道府県の色分け
covid.loc[covid['Rate'] >= covid['Rate'].quantile(.75), 'color']='red'
covid.loc[(covid['Rate'] < covid['Rate'].quantile(.75)) & (covid['Rate'] >= covid['Rate'].quantile(.25)), 'color']='blue'
covid.loc[(covid['Rate'] < covid['Rate'].quantile(.25)), 'color']='green'
covid.head()
# 地図の可視化
pref_colors={p:c for p, c in zip(covid['Prefecture'].values, covid['color'].values)}
image=jm.picture(pref_colors)
plt.figure(figsize=(10, 10))
plt.imshow(image)
plt.axis('off');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21901757548445244, 'fraction_numerical': 0.02658855340243353, 'mean_word_length': 8.21161825726141, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '208766', 'license': 'MIT', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1039, 'n_words': 132, 'path': 'week3/covid_stat.ipynb', 'repo_name': 'UTDataMining/2020A', 'size': '2219'}