Find out the age and number of winnings of prefectural governors nationwide

From the Governor's File of the National Governors' Association, the incumbent governor Scraping

import datetime
import re

import pandas as pd
import matplotlib.pyplot as plt


def wareki2date(s):

    m = re.search("(Showa|Heisei|Reiwa)([ 0-9 yuan]{1,2})Year( [0-9]{1,2})Moon([ 0-9]{1,2})Day", s)

    if m:

        year, month, day = [1 if i == "Former" else int(i.strip()) for i in m.group(2, 3, 4)]

        if m.group(1) == "Showa":
            year += 1925
        elif m.group(1) == "Heisei":
            year += 1988
        elif m.group(1) == "Reiwa":
            year += 2018

        return pd.Timestamp(year, month, day)

    else:
        return pd.NaT


df = pd.read_html("http://www.nga.gr.jp/app/chijifile/", attrs={"summary": "Search result list"})[0]

#Convert Japanese calendar to Western calendar
df["Birthday"] = df["Birthday"].apply(wareki2date)
df["Election date"] = df["Election date"].apply(wareki2date)
df["Term expiration date"] = df["Term expiration date"].apply(wareki2date)
df["Inauguration date"] = df["Inauguration date"].apply(wareki2date)

df["age"] = df["age"].str.rstrip("age").astype(int)

age

df["age"].value_counts(bins=[20,40,45,50,55,60,65,70,75,80]).sort_index().plot.bar()

ages.png

df["age"].describe()

count 47.000000 mean 61.680851 std 9.273868 min 39.000000 25% 56.000000 50% 60.000000 75% 69.500000 max 78.000000 Name: age, dtype: float64

Number of wins

df["Number of wins"].describe()

count 47.000000 mean 2.765957 std 1.447828 min 1.000000 25% 1.000000 50% 3.000000 75% 4.000000 max 7.000000 Name: Number of wins, dtype: float64

Japan Association of City Mayors

The list of Japan Association of City Mayors only lists names.

Recommended Posts

Find out the age and number of winnings of prefectural governors nationwide
Maya | Find out the number of polygons in the selected object
Python --Find out number of groups in the regex expression
How to find out the number of CPUs without using the sar command
I checked the number of closed and opened stores nationwide by Corona
Find the number of days in a month
Find out the day of the week with datetime
Projecet Euler 12 Find the number of divisors without division.
Find out the location of Python class definition files.
relation of the Fibonacci number series and the Golden ratio
Find out the version of the language you are running
I checked out the versions of Blender and Python
Find out the location of packages installed with pip
Find out the maximum number of characters in multi-line text stored in a data frame
[Python] A program to find the number of apples and oranges that can be harvested
How to find the optimal number of clusters in k-means
Find out the apparent width of a string in python
10. Counting the number of lines
Get the number of digits
Calculate the number of changes
Find the critical path of PERT using breadth-first search and depth-first search
Count the number of Thai and Arabic characters well in Python
Find out the mystery change of Pokédex description by Levenshtein distance
Find the distance from latitude and longitude (considering the roundness of the earth).
Find the waypoint from latitude and longitude (considering the roundness of the earth).
Find the intersection of a circle and a straight line (sympy matrix)
[Completed version] Try to find out the number of residents in the town from the address list with Python
Find the definition of the value of errno
The story of Python and the story of NaN
Get the number of views of Qiita
Calculation of the number of Klamer correlations
Get the number of Youtube subscribers
Find the inertial spindle and moment of inertia from the inertial tensor with NumPy
Graph of the history of the number of layers of deep learning and the change in accuracy
I tried to visualize the age group and rate distribution of Atcoder
Find the general terms of the Tribonacci sequence with linear algebra and Python
Get the number of articles accessed and likes with Qiita API + Python
Find out the name of the method that called it from the method that is python
CCC: coding crash course (5) Find out the frequency of words and letters that appear in Steve Jobs speeches