[Python] Representing the number of complaints from life insurance companies in a bar graph
Created with reference to
Convert PDF of details of complaint breakdown to csv with pdfplumber and visualize Visualization of details of life insurance company complaints
import requests
from bs4 import BeautifulSoup
url = "https://www.seiho.or.jp/member/complaint/"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
}
r = requests.get(url, headers=headers)
r.raise_for_status()
soup = BeautifulSoup(r.content, "html.parser")
result = []
for tag in soup.select("div.headMod04.mt30"):
data = []
data.append(tag.h3.get_text(strip=True).replace("Co., Ltd.", ""))
for table in tag.find_next_siblings("table", class_=["mt10", "mt15"], limit=2):
for td in table.select("tr > td.taR"):
f = float(td.get_text(strip=True).rstrip("subject%").replace(",", ""))
data.append(int(f) if f.is_integer() else f)
result.append(data)
import pandas as pd
df = pd.DataFrame(
result,
columns=[
"Insurance company name",
"Number of complaints",
"New contract relationship",
"Storage related",
"Conservation relations",
"Insurance money",
"Other",
"Number of in-force contracts",
"Number of customers",
],
).set_index("Insurance company name")
df
Insurance company name | Number of complaints | New contract relationship | Storage related | Conservation relations | Insurance money | Other | Number of in-force contracts | Number of customers | Complaint ratio |
---|---|---|---|---|---|---|---|---|---|
AXA Life Insurance | 4909 | 12.9 | 5.9 | 19.5 | 22.2 | 39.4 | 4.76064e+06 | 2.58086e+06 | 0.00190208 |
AXA Direct Life Insurance | 102 | 39.2 | 11.8 | 16.7 | 19.6 | 12.7 | 159640 | 120100 | 0.000849292 |
Asahi Mutual Life Insurance Company | 2895 | 14.4 | 7.3 | 25.5 | 13.2 | 39.7 | 7.77216e+06 | 1.94576e+06 | 0.00148785 |
Aflac life insurance | 12699 | 22.9 | 12.8 | 27.4 | 24.8 | 12 | 2.43943e+07 | 1.52941e+07 | 0.000830322 |
Aeon Allianz Life Insurance | 11 | 0 | 0 | 0 | 100 | 0 | 16219 | 16219 | 0.000678217 |
SBI Life Insurance | 72 | 52.8 | 4.2 | 13.9 | 16.7 | 12.5 | 115621 | 102485 | 0.000702542 |
NN Life Insurance | 163 | 8.6 | 15.3 | 49.1 | 14.1 | 12.9 | 504097 | 186308 | 0.000874895 |
FWD Fuji Life Insurance | 1098 | 22 | 12.4 | 11.1 | 24.3 | 30.1 | 1.4471e+06 | 1.07855e+06 | 0.00101803 |
ORIX Life Insurance | 6587 | 25 | 8.2 | 15.3 | 39.1 | 12.5 | 4.69599e+06 | 4.69599e+06 | 0.00140269 |
Cardif life insurance | 31 | 61.3 | 0 | 9.7 | 16.1 | 12.9 | 8891 | 1.33126e+06 | 2.32862e-05 |
Japan Post Insurance | 48859 | 87.9 | 1.4 | 5.2 | 4 | 1.4 | 1.79239e+07 | 1.0281e+07 | 0.00475235 |
Crédit Agricole Life Insurance | 10 | 40 | 0 | 10 | 20 | 30 | 59089 | 52001 | 0.000192304 |
Gibraltar Life Insurance | 7783 | 4.8 | 13.4 | 42.6 | 22.5 | 16.7 | 6.41288e+06 | 6.41288e+06 | 0.00121365 |
Sumitomo Life Insurance Company | 11698 | 6.7 | 7.1 | 32.6 | 23.5 | 30 | 1.14377e+07 | 6.93738e+06 | 0.00168623 |
Sony life insurance | 3871 | 9.4 | 12.2 | 43.1 | 14.7 | 20.7 | 8.16556e+06 | 3.70221e+06 | 0.00104559 |
Sony Life with Life Insurance | 200 | 12 | 0 | 58.5 | 7.5 | 22 | 99225 | 87701 | 0.00228048 |
SOMPO Himawari Life Insurance (former Sompo Japan Nipponkoa Himawari Life Insurance) | 1268 | 13.5 | 13.8 | 29.8 | 25 | 17.9 | 4.19732e+06 | 2.9958e+06 | 0.000423259 |
Dai-ichi Life Insurance | 5728 | 9.2 | 6.7 | 23.9 | 15.3 | 44.8 | 2.07372e+07 | 8.03565e+06 | 0.000712824 |
Daiichi Frontier Life Insurance | 706 | 37.8 | 0 | 16.6 | 6.8 | 38.8 | 1.59389e+06 | 1.25441e+06 | 0.000562816 |
Taiju Life Insurance (formerly Mitsui Life Insurance) | 2495 | 14.6 | 7.5 | 22.9 | 18.2 | 36.8 | 2.58049e+06 | 1.82014e+06 | 0.00137078 |
Daido Life Insurance | 1431 | 10.3 | 8.5 | 40 | 15.7 | 25.6 | 2.08751e+06 | 798324 | 0.00179251 |
Taiyo Life Insurance | 1328 | 30.6 | 8.1 | 22.1 | 17.6 | 21.6 | 7.69601e+06 | 2.03224e+06 | 0.000653466 |
Zurich Life Insurance Company Limited | 1794 | 29.1 | 16.1 | 18.5 | 10 | 26.3 | 1.17402e+06 | 993181 | 0.00180632 |
T & D Financial Life Insurance | 170 | 19.4 | 5.9 | 40.6 | 21.8 | 12.4 | 329886 | 281942 | 0.000602961 |
Tokio Marine & Nichido Life Insurance | 2809 | 15.3 | 14.2 | 30 | 7.8 | 32.6 | 5.97493e+06 | 3.54450e+06 | 0.000792494 |
Nippon Wealth Life Insurance | 379 | 4.7 | 6.1 | 28.8 | 39.1 | 21.4 | 332853 | 274786 | 0.00137926 |
Nippon Life Insurance Company | 9210 | 11.1 | 9.4 | 37.8 | 14.6 | 27 | 3.30507e+07 | 1.21611e+07 | 0.00075733 |
Neo First Life Insurance | 299 | 36.5 | 10.7 | 14.4 | 22.4 | 16.1 | 379944 | 379944 | 0.000786958 |
Hanasaku Life Insurance | 86 | 52.3 | 15.1 | 7 | 16.3 | 9.3 | 74374 | 70904 | 0.00121291 |
Fukoku Life Insurance Company | 2873 | 8.8 | 13.5 | 35.1 | 25 | 17.6 | 3.79431e+06 | 1.7536e+06 | 0.00163834 |
Fukoku Shinrai Life Insurance | 1300 | 2.5 | 6.5 | 13.7 | 16.2 | 61.2 | 591927 | 449197 | 0.00289405 |
Prudential Life Insurance | 2055 | 19.2 | 12.9 | 40.7 | 12.6 | 14.5 | 4.181e+06 | 1.7134e+06 | 0.00119937 |
PGF Life (Prudential Gibraltar Financial Life Insurance) | 826 | 17.4 | 8.2 | 38.1 | 17.1 | 19.1 | 584295 | 518397 | 0.00159337 |
Manulife life insurance | 1089 | 7.3 | 13.1 | 19.2 | 17.1 | 43.3 | 1.56167e+06 | 1.04053e+06 | 0.00104658 |
Mitsui Sumitomo Insurance Aioi Life Insurance | 765 | 15.6 | 10.1 | 17.1 | 31.2 | 26 | 3.91038e+06 | 3.91038e+06 | 0.000195633 |
Mitsui Sumitomo Primary Life Insurance | 561 | 20 | 0 | 18.7 | 10.3 | 51 | 1.20054e+06 | 987210 | 0.000568268 |
Midori Life Insurance | 174 | 63.8 | 4.6 | 7.5 | 13.8 | 10.3 | 249168 | 203418 | 0.000855382 |
Meiji Yasuda Life Insurance Company | 7094 | 9.9 | 8.9 | 32.2 | 21.9 | 27.1 | 1.23014e+07 | 7.04229e+06 | 0.00100734 |
MetLife Life Insurance | 10905 | 12 | 10.7 | 28 | 24.1 | 25.2 | 9.43914e+06 | 9.43914e+06 | 0.0011553 |
Medicare Life Insurance | 388 | 33 | 19.6 | 14.9 | 20.6 | 11.9 | 778313 | 702099 | 0.000552629 |
Lifenet Life Insurance | 1114 | 54.7 | 7.9 | 6 | 8 | 23.4 | 387775 | 246432 | 0.00452052 |
Rakuten Life Insurance | 678 | 21.4 | 14.5 | 19.9 | 29.2 | 15 | 844748 | 499039 | 0.00135861 |
import japanize_matplotlib
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams["figure.dpi"] = 200
df["Number of complaints"].plot.barh(figsize=(15, 15))
df["Complaint ratio"] = df["Number of complaints"] / df["Number of customers"]
df["Complaint ratio"].plot.barh(figsize=(15, 15))
df1 = df.reindex(columns = ["New contract relationship", "Storage related", "Conservation relations", "Insurance money", "Other"])
df1.plot.barh(stacked=True, figsize=(15, 15))
Recommended Posts