Let's check the population transition of Matsue City, Shimane Prefecture with open data

Introduction

I learned that you can get the transition of population by CSV on the following site, so I will download it immediately and summarize the confirmed procedure.

Shimane no Satozukuri Support Site Open Data

environment

Preparation

Library installation

Install the library so that Japanese is displayed correctly for visualization.

python


!pip install japanize_matplotlib

Success if the following is displayed.

Collecting japanize_matplotlib
  Downloading https://files.pythonhosted.org/packages/2c/aa/3b24d54bd02e25d63c8f23bb316694e1aad7ffdc07ba296e7c9be2f6837d/japanize-matplotlib-1.1.2.tar.gz (4.1MB)
     |████████████████████████████████| 4.1MB 2.8MB/s 
Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from japanize_matplotlib) (3.2.2)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->japanize_matplotlib) (2.8.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->japanize_matplotlib) (2.4.7)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->japanize_matplotlib) (1.2.0)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->japanize_matplotlib) (0.10.0)
Requirement already satisfied: numpy>=1.11 in /usr/local/lib/python3.6/dist-packages (from matplotlib->japanize_matplotlib) (1.18.5)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.1->matplotlib->japanize_matplotlib) (1.12.0)
Building wheels for collected packages: japanize-matplotlib
  Building wheel for japanize-matplotlib (setup.py) ... done
  Created wheel for japanize-matplotlib: filename=japanize_matplotlib-1.1.2-cp36-none-any.whl size=4120191 sha256=320f4fbd50cf3f232030ce922031d1c926db2e98033cbc3059fa06e5b28d585d
  Stored in directory: /root/.cache/pip/wheels/9c/f9/fc/bc052ce743a03f94ccc7fda73d1d389ce98216c6ffaaf65afc
Successfully built japanize-matplotlib
Installing collected packages: japanize-matplotlib
Successfully installed japanize-matplotlib-1.1.2

Environmental setting

python


import matplotlib.pyplot as plt
import japanize_matplotlib 
import seaborn as sns

sns.set(font="IPAexGothic")

Data reading

Since the data from 2012 to 2019 can be downloaded, execute the following code to load it.

python


import pandas as pd

url_base = "https://satodukuri.pref.shimane.lg.jp/info/opendata/download?nendo=0000&fmt=csv"

df = pd.DataFrame()

for y in range(2012, 2020):
    url = url_base.replace("0000", str(y))
    df = pd.concat([df, pd.read_csv(url)])

df.shape

You can see that there are 2384 rows of data in various ways.

(2384, 109)

Data confirmation

python


df.info()

Execution result

<class 'pandas.core.frame.DataFrame'>
Int64Index: 2384 entries, 0 to 297
Columns: 109 entries,Year to Female 90 years old and over Estimated survival rate
dtypes: float64(56), int64(47), object(6)
memory usage: 2.1+ MB

There are 109 rows ... surprisingly many.

python


for col in df.columns:
    print(col)

Execution result.

year
District code
District name
Municipal name
Municipalities before the merger
Regional setting
Designation of site support area
Annotation
Total male and female population
Number of households
Aging rate
Late aging rate
Population increase / decrease rate
4 years old or younger ratio
Ratio of women in their 20s and 30s
Junior high school population ratio
Elementary school population ratio
Working-age population ratio
Young age group ratio
Elementary school population
Junior high school population
Number of population maintenance groups
Number of elementary school students maintained
Male population 0-4 years old
Male population 5-9 years old
Male population 10-14 years
Male population 15-19 years old
Male population 20-24 years old
Male population 25-29 years old
Male population 30-34 years old
Male population 35-39 years old
Male population 40-44 years
Male population 45-49 years old
Male population 50-54 years old
Male population 55-59 years old
Male population 60-64 years old
Male population 65-69 years old
Male population 70-74 years old
Male population 75-79 years
Male population 80-84 years
Male population 85-89 years
Male population 90-94 years old
Male population 95-99 years old
Male population over 100 years old
Female population 0-4 years old
Female population 5-9 years old
Female population 10-14 years old
Female population 15-19 years old
Female population 20-24 years old
Female population 25-29 years old
Female population 30-34 years old
Female population 35-39 years old
Female population 40-44 years old
Female population 45-49 years old
Female population 50-54 years old
Female population 55-59 years old
Female population 60-64 years old
Female population 65-69 years old
Female population 70-74 years old
Female population 75-79 years
Female population 80-84 years old
Female population 85-89 years
Female population 90-94 years old
Female population 95-99 years old
Female population over 100 years old
Male cohort rate of change (0-4 years)
Male cohort change rate (5-9 years old)
Male cohort rate of change (10-14 years)
Male cohort change rate (15-19 years old)
Male cohort change rate (20-24 years old)
Male cohort change rate (25-29 years old)
Male cohort change rate (30-34 years old)
Male cohort change rate (35-39 years old)
Male cohort change rate (40-44 years old)
Male cohort change rate (45-49 years old)
Male cohort change rate (50-54 years old)
Male cohort change rate (55-59 years old)
Male cohort change rate (60-64 years old)
Male cohort change rate (65-69 years old)
Male cohort change rate (70-74 years old)
Male cohort rate of change (75-79 years)
Male cohort change rate (80-84 years old)
Male cohort change rate (85-89 years old)
Male cohort change rate (90-94 years old)
Male cohort change rate (95-99 years old)
Male cohort change rate (100 years and over)
Estimated survival rate for men over 90 years old
Female cohort change rate (0-4 years old)
Female cohort change rate (5-9 years old)
Female cohort change rate (10-14 years old)
Female cohort change rate (15-19 years old)
Female cohort change rate (20-24 years old)
Female cohort change rate (25-29 years old)
Female cohort change rate (30-34 years old)
Female cohort change rate (35-39 years old)
Female cohort change rate (40-44 years old)
Female cohort change rate (45-49 years old)
Female cohort change rate (50-54 years old)
Female cohort change rate (55-59 years old)
Female cohort change rate (60-64 years old)
Female cohort change rate (65-69 years old)
Female cohort change rate (70-74 years old)
Female cohort change rate (75-79 years old)
Female cohort change rate (80-84 years old)
Female cohort change rate (85-89 years old)
Female cohort change rate (90-94 years old)
Female cohort change rate (95-99 years old)
Female cohort change rate (100 years and over)
Estimated survival rate for women over 90 years old

... pretty fine.

Data display

Confirm the name of the municipality

python


df["Municipal name"].value_counts()
Izumo City 344
Matsue City 256
Unnan City 240
Oda City 216
Hamada City 200
Yasugi City 192
Masuda City 160
Gotsu City 160
Okinoshima Town 120
Misato Town 104
Onan Town 96
Tsuwano Town 96
Okuizumo Town 72
Yoshika Town 40
Iinan Town 40
Kawamoto Town 24
Nishinoshima Town 8
Ama 8
Chibu Village 8
Name:Municipal name, dtype: int64

Hmmmm ...

Confirm the district name of Matsue City

python


df[df["Municipal name"] == "Matsue"]["District name"].value_counts()
Akika 8
Abomination 8
Raw horse 8
Kashima 8
Johoku 8
Yito 8
Higashiizumo 8
Ohno 8
Izumo Township 8
Honjo 8
Hokki 8
Mihonoseki 8
Tsuda 8
Koshibara 8
Mochida 8
Kawazu 8
Shimane 8
Saiga 8
Oba 8
Asahi 8
Joto 8
Shinji 8
Nogi 8
Yatsuka 8
Iya 8
Asakumi 8
Tamayu 8
Takeya 8
Furue 8
Shiragata 8
Yakumo 8
Josai 8
Name:District name, dtype: int64

Hmmmm ...

Visualization

For the time being, I will draw a graph of the "total number of men and women," "elementary school population," "junior high school population," and "aging rate," which seem to be interesting.

python


df_area = df.groupby(["Municipal name", "year"]).sum()

df_area.loc["Matsue"]["Total male and female population"].plot(figsize=(15,4))
plt.show()

df_area.loc["Matsue"]["Elementary school population"].plot(figsize=(15,4))
plt.show()

df_area.loc["Matsue"]["Junior high school population"].plot(figsize=(15,4))
plt.show()

df_area = df.groupby(["Municipal name", "year"]).mean()

df_area.loc["Matsue"]["Aging rate"].plot(figsize=(15,4))
plt.show()

Execution result.

Total male and female population

Unknown.png

Elementary school population

Unknown-2.png

Junior high school population

Unknown-3.png

Aging rate

Unknown-4.png

... not good.

Recommended Posts

Let's check the population transition of Matsue City, Shimane Prefecture with open data
Let's simulate the transition of infection rate with respect to population density with python
Let's use the open data of "Mamebus" in Python
Let's visualize the rainfall data released by Shimane Prefecture
Let's visualize the river water level data released by Shimane Prefecture
The story of verifying the open data of COVID-19
Check the existence of the file with python
Let's calculate the transition of the basic reproduction number of the new coronavirus by prefecture
Check the date of the flag duty with Python
The transition of baseball as seen from the data
Check the status of your data using pandas_profiling
Extract the band information of raster data with python
I tried to display the point cloud data DB of Shizuoka prefecture with Vue + Leaflet
Preprocessing of prefecture data
Try scraping the data of COVID-19 in Tokyo with Python
A network diagram was created with the data of COVID-19.
Let's utilize the railway data of national land numerical information
Let's make the analysis of the Titanic sinking data like that
Let's execute the command on time with the bot of discord
Check the memory status of the server with the Linux free command
Check the scope of local variables with the Python locals function.
Let's touch the API of Netatmo Weather Station with Python. #Python #Netatmo
Check the operating status of the server with the Linux top command
Let's guess the development status of the city from the satellite image.
The story of rubyist struggling with python :: Dict data with pycall
[Homology] Count the number of holes in data with Python
Let's visualize the number of people infected with coronavirus with matplotlib
Let's use the distributed expression of words quickly with fastText!
Try to extract the features of the sensor data with CNN