%matplotlib inline
import pandas as pd
import numpy as np
import seaborn as sns
from pandas import Series, DataFrame
from matplotlib import pyplot as plt
World Religion Map: https://www.kaggle.com/umichigan/world-religions/downloads/regional.csv/notebook
Global = pd.read_csv('csv/global.csv', index_col=0)
national = pd.read_csv('csv/national.csv', index_col=0)
regional = pd.read_csv('csv/regional.csv', index_col=0)
Global.head(10)
regional.head(10)
national.head(10)
アメリカ以外の国も含まれていることがわかる
national.sample(10)
国名でグループすることにより、複数の国名を1つにし、count()で各行を数える
national.groupby(['state']).size().count()
print(national['state'].unique())
Global.shinto_all.plot(kind='bar', title='世界の神道人口/年代', rot=45)
(Global['shinto_all'] / Global['world_population']).plot('bar', title='世界人口からみる神道信者数')
national = pd.read_csv('csv/national.csv',
usecols=[0, 1,25,29,38,39,76], # 使う列は 1,25,29,38,39,76列
index_col=1) # indexはstateに
national.head(3)
national.head(3)[['year', 'religion_all']]
national['Japan':'Japan']
.loc['インデックスの行','列']
national.loc['Japan','religion_all']
df_jp = (national.loc['Japan','shinto_all'] + national.loc['Japan','buddhism_all'] / national.loc['Japan','religion_all']).sort_values(ascending=False)
df_jp.plot('bar', title='日本における全宗教人口と神道+仏教人口との割合', rot=45)
インデックスを国名にして日本を摘出したことにより、インデックスに年代が表示できない
列と行の中の項目を指定することはできないのだろうか....
先生のアドバイスにより、以下のように解説
日本をloc(行ラベル)で指定し、df_jpに代入し、インデックスをset_index()で設定し、年代を指定
df_jp = national.loc['Japan']
df_jp = df_jp.set_index('year')
df_jp['shinto_and_buddhism_ratio'] = df_jp['shinto_all'] + df_jp['buddhism_all'] / df_jp['religion_all']
df_jp['shinto_and_buddhism_ratio'].plot('bar', title='日本における全宗教人口と神道+仏教人口との割合', rot=45)
2005年から他の宗教より神道+仏教人口が上回っていることがわかる
日本の人口から神道+仏教人口を割って比率でみることで、人口増加の要因から離れてみることができる
df_jp = national.loc['Japan']
df_jp = df_jp.set_index('year')
df_jp['shinto_and_buddhism_ratio'] = df_jp['shinto_all'] + df_jp['buddhism_all'] / df_jp['population']
df_jp['shinto_and_buddhism_ratio'].plot('bar', title='日本における全宗教人口と神道+仏教人口との割合', rot=45)
神道+仏教人口が、2005年から人口より上回っている。
神道が文化に溶け込んでいる日本では、神道+他の宗教を支持する人が多いということだろうか。
では、人口数が宗教人口より上回っている国は他にもあるのだろうか...
national['total_percent'].sort_values(ascending=False)
神道人口数をどう計算したのかは不明だが、日本以外でもCuba、Haitiがあるよう。
TIP: index_col=1を指定するとIndex部を読み込めなくエラーが出るので、削除すること
national = pd.read_csv('csv/national.csv', usecols=[0, 1,25,29,38,39])
plt.figure(figsize=(27, 8))
sns.heatmap(national.pivot('year', 'state', 'shinto_all'), cmap='Blues')
神道は日本のみで栄えていることがわかる
plt.figure(figsize=(27, 8))
sns.heatmap(national.pivot('year', 'state', 'buddhism_all'), cmap='Greens')
国別だと200の国名が表示できなく、国を特定できないが日本以外でも仏教徒がいることがわかる
regional = pd.read_csv('csv/regional.csv')
sns.heatmap(regional.pivot('year', 'region', 'shinto_all'), cmap='Blues')
神道人口はアジア(日本のみ)で年々急増している > 人口増加による急増
sns.heatmap(regional.pivot('year', 'region', 'buddhism_all'), cmap='Greens')
仏教人口はアジアのみで年々急増している > 人口増加による急増
national = pd.read_csv('csv/national.csv', usecols=[0, 1,25,29,38,39])
sns.barplot(x= national.year, y= national[national.state=='Japan']['shinto_all'],palette= 'Blues')
national = pd.read_csv('csv/national.csv', usecols=[0, 1,25,29,38,39])
sns.barplot(x= national.year, y= national[national.state=='Japan']['buddhism_all'],palette= 'Greens')
sns.heatmap(regional.pivot('year', 'region', 'world_population'), cmap='Reds')
世界全体で人口が増加していることがわかる
sns.heatmap(regional.pivot('year', 'region', 'religion_all'), cmap='Reds')
宗教人口はなぜかアジアだけ増加していることがわかる
Global = pd.read_csv('csv/global.csv')
cols= ['year','christianity_all','islam_all','hinduism_all','buddhism_all','noreligion_all','syncretism_all','christianity_percent','hinduism_percent','islam_percent','buddhism_percent','syncretism_percent','noreligion_percent']
Global= Global[cols]
for col in Global.columns:
if '_all' in col:
ax= plt.plot(Global.index, Global[col],label= col, linewidth= 3)
plt.title('宗教別支持者数')
plt.legend(bbox_to_anchor= (-.2,-.5,1.4,.5), mode= 'expand', loc=3,ncol=3,fontsize= 14)
plt.xticks(size=14)
plt.yticks(size=14)
クリスチャンが多く、人口増加で右上がり
Global = pd.read_csv('csv/global.csv')
cols= ['christianity_all','islam_all','hinduism_all','buddhism_all','shinto_all','noreligion_all','syncretism_all']
Global= Global[cols]
plt.figure(figsize=(13, 11))
sns.heatmap(Global.corr(), square=True, cmap='Blues', annot=True, fmt="1.1f")
plt.title('世界の宗教相対関係')
4大宗教のキリスト教、イスラム教、ヒンデゥー教、仏教の相対値が濃くなっている。
シンクレティズム(syncretism)は、重層信仰という意味で、日本の神仏習合(神道+仏教)の現れだが、色の変化はイスラム教より顕著でない。
人口、宗教人口、他の宗教も追加
Global = pd.read_csv('csv/global.csv')
cols= ['population','religion_all','christianity_all','judaism_all','islam_all','hinduism_all','buddhism_all','shinto_all','zoroastrianism_all','sikhism_all','baha’i_all','jainism_all','animism_all','noreligion_all','syncretism_all']
Global= Global[cols]
plt.figure(figsize=(13, 11))
sns.heatmap(Global.corr(), square=True, cmap='Blues', annot=True, fmt="1.1f")
plt.title('世界の宗教相対関係 ver.2')
他の記述方法
cols = Global.corr()
order = ['population','religion_all','christianity_all','judaism_all','islam_all','hinduism_all','buddhism_all','shinto_all','zoroastrianism_all','sikhism_all','baha’i_all','jainism_all','animism_all','noreligion_all','syncretism_all']
cols[order]
cols_ordered = cols[order]
plt.figure(figsize=(13, 11))
sns.heatmap(cols_ordered, square=True, cmap='Blues', annot=True, fmt="1.1f")
plt.title('世界の宗教相対関係 ver.3')
regional= pd.read_csv('csv/regional.csv')
cols= ['year','population','christianity_all','judaism_all','islam_all','hinduism_all','buddhism_all','shinto_all','zoroastrianism_all','sikhism_all','baha’i_all','jainism_all','animism_all','noreligion_all','syncretism_all']
regionals= regional[cols]
regionals
regional = pd.read_csv('csv/regional.csv')
plt.figure(figsize=(13, 8))
sns.heatmap(regional.pivot('region', 'year', 'noreligion_all'), cmap='Purples')
アジアで急激に無宗教人口が多くなっている
colormap = plt.cm.Set2
noreligion_year = regional.groupby(['year','region']).noreligion_all.sum()
noreligion_year.unstack().plot(kind='bar',stacked=True, colormap= colormap, grid=False, figsize=(14,8) ,
legend=False, title='無宗教人口の割合の変化')
plt.legend(bbox_to_anchor= (-.2,-.6,1.4,.5), mode= 'expand', loc=1, ncol=5, fontsize= 14)
plt.show()
アジア(青)が一番、無宗教人口が増えている
[cols]の中身は[['region'....'syncretism_all']]として[ ]も含めて代入されるため、Dataframeになる
cols= ['year','region','population','christianity_all','judaism_all','islam_all','hinduism_all','buddhism_all','shinto_all','zoroastrianism_all','sikhism_all','baha’i_all','jainism_all','animism_all','noreligion_all','syncretism_all']
regionals= regional[cols]
regionals