インターネットが無くてはならない存在となった現代社会において、世界中でインターネットにアクセスできる状況はどのようになっているのか。
国、地域、人口、使用率などのデータに基づいて分析を行う。
ライブラリのインポート
from zipfile import ZipFile
from io import BytesIO
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import plotly.express as px
import japanize_matplotlib
sns.set(font='IPAexGothic')
データファイルの名前を取得
zf = ZipFile('data.zip')
zf.namelist()
データフレームとして読み込む
internet = pd.read_csv(BytesIO(zf.read(zf.namelist()[1])))
broadband = pd.read_csv(BytesIO(zf.read(zf.namelist()[2])))
people = pd.read_csv(BytesIO(zf.read(zf.namelist()[3])))
internet データフレームから2019年のデータを抽出
Entityでグループ化し、Internet_Usage の合計を算出
上位5カ国を表示
top_five = internet.query('Year == 2019')
top_five = top_five.groupby('Entity')['Internet_Usage'].sum()
top_five = top_five.sort_values(ascending=False).head(5)
top_five
people データフレームから前述5カ国のみを抽出
2019年でデータをソート
Year, Entity, Users のみにデータを限定して表示
countries_users_2019 = people[people['Entity'].isin(top_five.index)]
countries_users_2019 = countries_users_2019 [(countries_users_2019 ['Year'] == 2019)].sort_values(ascending=False, by ='Users' )
countries_users_2019 = countries_users_2019[['Year', 'Entity', 'Users' ]]
countries_users_2019
| アラブ首長国連邦 | 9,133,361人 |
| デンマーク | 5,682,653人 |
| クウェート | 4,420,795人 |
| カタール | 2,797,495人 |
| バーレーン | 1,489,735人 |
internetデータフレームからNan値を削除
World値以外で新しいデータフレームを作成
df1として外部データを取得
カラム名を変更
2つのデータをマージして新たなデータフレームを作成
new = internet.dropna(axis=0, subset=('Code', ))
new = new.query ('Entity != "World"')
df1 = pd.read_html('https://statisticstimes.com/geography/countries-by-continents.php', thousands=None, decimal=',')
may = df1[2]
may.rename (columns= {'ISO-alpha3 Code':'Code'}, inplace = True )
countries = new.merge(may, how = "left")
aes = 'Eastern Africa', 'Southern Africa'
aes1 = countries[countries['Region 1'].isin(aes)]
aes1 = aes1.query('Year == 2019')
top_five_aes = aes1.groupby('Entity')['Internet_Usage'].sum().sort_values(ascending=False).head(5)
top_five_aes
2019 年にアフリカ東部および南部でインターネットの使用量が最も多かった国は2カ国のみ
2017 年の上位 5 か国は以下
awc = 'Western Africa', 'Central Africa'
awc1 = countries[countries['Region 1'].isin(awc)]
awc1 = awc1.query('Year == 2017')
top_five_awc = awc1.groupby('Entity')['Internet_Usage'].sum().sort_values(ascending=False).head(5)
top_five_awc
アフリカ西部および中部でインターネットの使用量が最も多かった2019年のデータはなし、2018年は1カ国のみ
2017 年にアフリカ西部および中部でインターネットの使用量が最も多かった上位 5 か国
lac = ["Latin America and the Caribbean"]
lac1 = countries[countries['Region 2'].isin(lac)]
lac1 = lac1.query('Year == 2019')
top_five_lac = lac1.groupby('Entity')['Internet_Usage'].sum().sort_values(ascending=False).head(5)
top_five_lac
2019 年にラテンアメリカおよびカリブ海地域でインターネットの使用量が最も多かった上位 5 か国
eap1 = countries[(countries['Region 1'] == 'Eastern Asia') | (countries['Continent'] == 'Oceania')]
eap1 = eap1.query('Year == 2018')
top_five_eap = eap1.groupby('Entity')['Internet_Usage'].sum().sort_values(ascending=False).head(5)
top_five_eap
2018 年に東アジア太平洋地域でインターネットの使用量が最も多かった上位 5 か国
sa = ["Southern Asia"]
sa1 = countries[countries['Region 1'].isin(sa)]
sa1 = sa1.query('Year == 2017')
top_five_sa = sa1.groupby('Entity')['Internet_Usage'].sum().sort_values(ascending=False).head(5)
top_five_sa
2017 年に南アジアでインターネットの使用量が最も多かった上位 5 か国
na = ["North America"]
na1 = countries[countries['Continent'].isin(na)]
na1 = na1.query('Year == 2019')
top_five_na = na1.groupby('Entity')['Internet_Usage'].sum().sort_values(ascending=False).head(5)
top_five_na
2019 年に北米でインターネットの使用量が最も多かった上位 5 か国
eu = 'Austria', 'Belgium', 'Bulgaria', 'Croatia', 'Cyprus', 'Czechia', 'Denmark', 'Estonia', 'Finland', 'France', 'Germany', 'Greece', 'Hungary', 'Ireland', 'Italy', 'Latvia', 'Lithuania', 'Luxembourg', 'Malta', 'Netherlands', 'Poland', 'Portugal', 'Romania', 'Slovakia', 'Slovenia', 'Spain', 'Sweden'
eu1 = internet[internet['Entity'].isin(eu)]
eu1 = eu1.query('Year == 2019')
top_five_eu = eu1.groupby('Entity')['Internet_Usage'].sum().sort_values(ascending=False).head(5)
top_five_eu
seven = internet
region3 = 'Africa Eastern and Southern', 'Africa Western and Central', 'Latin America & Caribbean', 'East Asia & Pacific', 'South Asia', 'North America', 'European Union'
seven_regions = internet[internet['Entity'].isin(region3)]
seven_regions.Entity.unique()
plt.figure(figsize=(14,7))
sns.lineplot(data=seven_regions,
x = 'Year',
y = 'Internet_Usage',
hue = 'Entity',
palette = 'inferno')
plt.title('地域ごとのインターネット使用量',size=20)
plt.xlabel('年', labelpad=10, size=14)
plt.ylabel("使\n用\n量", labelpad=18, size=14, rotation=0, va='center')
plt.show()
seven_regions = seven_regions.query ('Year < 2018')
fig = px.bar(seven_regions,
x="Entity",
y="Internet_Usage",
color="Entity",
color_discrete_sequence=px.colors.sequential.Inferno,
animation_frame="Year",
animation_group="Entity",
title = """
7 つの地域における 1990 年から 2017 年までの使用量の推移
""")
fig.update_layout(
margin=dict(l=0, r=0, t=30, b=0))
fig.show()
five = internet
replacers = {'South Asia':'Asia & Pacific','East Asia & Pacific':'Asia & Pacific', 'Africa Eastern and Southern':'Africa','Africa Western and Central':'Africa'}
five['Entity'] = five['Entity'].replace(replacers)
region = 'Africa', 'Latin America & Caribbean', 'Asia & Pacific', 'North America', 'European Union'
five_regions = five[five['Entity'].isin(region)]
plt.figure(figsize=(14,7))
sns.lineplot(data=five_regions,
x = 'Year',
y = 'Internet_Usage',
hue = 'Entity',
palette = 'inferno')
plt.title('5 つの地域におけるインターネット使用量の推移',size=20)
plt.xlabel('年', labelpad=10, size=14)
plt.ylabel("使\n用\n量", labelpad=18, size=14, rotation=0, va='center')
plt.show()
five_regions = five_regions.query ('Year < 2018')
fig = px.bar(five_regions,
x = "Entity",
y = "Internet_Usage",
color = "Entity",
color_discrete_sequence = px.colors.sequential.Inferno,
animation_frame = "Year",
animation_group = "Entity",
title = "5 つの地域における1990 年から 2017 年までの インターネット使用量の推移")
fig.update_layout(
margin=dict(l=0, r=0, t=30, b=0))
fig.show()
other = 'World', 'Asia', 'Upper-middle-income countries', 'High-income countries', 'Lower-middle-income countries', 'Europe', 'North America' , 'South America', 'Africa'
no_other = people[~people['Entity'].isin(other)]
no_other = no_other.query ('Year == 2020')
top_five_users = no_other.groupby('Entity')['Users'].sum().sort_values(ascending=False).head(5)
top_five_users
plt.figure(figsize=(14,7))
sns.barplot(x = top_five_users.index,
y = top_five_users,
palette = "inferno")
plt.title('2020年のインターネットユーザーが最も多い国トップ5',size=20)
plt.xlabel('国', labelpad=10, size=14)
plt.ylabel("利\n用\n者\n数", labelpad=18, size=14, rotation=0, va='center')
plt.show()
2020 年に最もユーザー数が多かった上位 5 か国
_data = internet.merge(broadband)
_data2019 = _data.query ('Year == 2019')
col1, col2 = "Internet_Usage", "Broadband_Subscriptions"
corr = _data2019['Internet_Usage'].corr(_data2019['Broadband_Subscriptions'])
print ("使用量とブロードバンド契約数の相関係数は ", round(corr, 2))
fig = plt.subplots(figsize=(8, 4))
x = _data2019['Internet_Usage']
y = _data2019['Broadband_Subscriptions']
plt.title('Correlation')
plt.scatter(x, y)
plt.plot(np.unique(x),
np.poly1d(np.polyfit(x, y, 1))(np.unique(x)),
color='orange')
plt.title('使用量とブロードバンド契約数の相関',size=20)
plt.xlabel('使用量', labelpad=10, size=14)
plt.ylabel("契\n約\n数", labelpad=18, size=14, rotation=0, va='center');
相関 0,56 は、中程度の正の線形関係を示します。
インターネット使用率が最も高い国はバーレーン、カタールなどの中東が上位を占めています。
アラブ首長国連邦、デンマークなど使用率の高い国では、ほとんどの人々がインターネットにアクセスできます。
一部の国ではデータが欠如していたので、2017, 2018, 2019 年で地域ごとに異なります。 EU は2019 年のデータに基づく結果となります。
ほぼ一貫してアメリカが最もインターネットの使用量が多い国となっています。
中国、インドの人口が多い国がユーザー数も多い国となっています。
インターネット使用量とブロードバンド契約数の相関係数は 0.56 となっており、相関関係が見られます。