――Recently, I got a life insurance policy from an acquaintance. ――But can you really trust the insurance company? ?? I thought, I looked at the number of complaints on this site. ――It's hard to understand because there are many complaints and many insurance companies ... --I tried to express the number of complaints as a bar graph using matplotlib of Python.
――Japan Post Insurance Co., Ltd. has the most complaints! ――But if you are an insurance company with a large number of contracts from the beginning, the number of complaints may also increase. ?? ??
from bs4 import BeautifulSoup
import pandas as pd
import re
import matplotlib.pyplot as plt
import requests
url = requests.get("https://www.seiho.or.jp/member/complaint/")
url.raise_for_status()
bs = BeautifulSoup(url.text, "html.parser")
#Express the number of complaints (cases) in a bar graph
#Insurance company name
#Since the name is long, delete "Life Insurance Co., Ltd."
company_name_list = [re.sub('Life insurance company','',i.get_text().replace('\n','') )
for i in bs.select('div.headMod04.mt30')]
#Number of complaints (cases)
claim_count_list = [int(((j.get_text())[:-1]).replace(',',''))
for i in bs.select('table.tblMod02.tblP2.mt10')
for j in i.select('td.vaM.taR')]
#Graph creation
plt.title("Number of complaints")
plt.xlabel('Name of Life Insurance Co., Ltd.')
plt.ylabel('Case')
plt.xticks(rotation=90, fontsize=8)
plt.bar(company_name_list,claim_count_list)
plt.show()
--Cardif Life Insurance Co., Ltd. has a high percentage of complaints! ――But since the number of contracts and complaints is small compared to the whole, it is delicate to simply decide as an insurance company with many complaints ... --The ratio of complaints between Japan Post Insurance Co., Ltd. and Lifenet Life Insurance Co., Ltd. is quite large ...
from bs4 import BeautifulSoup
import pandas as pd
import re
import matplotlib.pyplot as plt
import requests
url = requests.get("https://www.seiho.or.jp/member/complaint/")
url.raise_for_status()
bs = BeautifulSoup(url.text, "html.parser")
#Representing the percentage of complaints in a bar graph
#Insurance company name
#Since the name is long, delete "Life Insurance Co., Ltd."
company_name_list = [re.sub('Life insurance company','',i.get_text().replace('\n','') )
for i in bs.select('div.headMod04.mt30')]
#Number of complaints received by the company (cases)
claim_count_list = [int(((j.get_text())[:-1]).replace(',',''))
for i in bs.select('table.tblMod02.tblP2.mt10')
for j in i.select('td.vaM.taR')]
#Number of individual insurance policies (cases)
guest_number_list = [int((j.get_text())[:-1].replace(',',''))
for i in bs.select('table.tblMod02.tblP2.mt15')
for j in i.select('td.vaM.taR')]
guest_number_list = [guest_number_list[i] for i in range(len(guest_number_list)) if i%2 == 0]
#Complaint rate (%)
claim_rate_list = [(i/j) * 100 for i,j in zip(claim_count_list,guest_number_list)]
plt.title("Complaint rate")
plt.xlabel('Name of Life Insurance Co., Ltd.')
plt.ylabel('%')
plt.xticks(rotation=90, fontsize=8)
plt.bar(company_name_list,claim_rate_list)
plt.show()
――The breakdown of complaints looks the same overall
from bs4 import BeautifulSoup
import pandas as pd
import re
import matplotlib.pyplot as plt
import requests
url = requests.get("https://www.seiho.or.jp/member/complaint/")
url.raise_for_status()
bs = BeautifulSoup(url.text, "html.parser")
#Express the breakdown of complaints in a stacked bar graph
#Insurance company name
#Since the name is long, delete "Life Insurance Co., Ltd."
company_name_list = [re.sub('Life insurance company','',i.get_text().replace('\n','') )
for i in bs.select('div.headMod04.mt30')]
#Contents of the number of items
claim_detail = ['New contract relationship','Storage related','Conservation relations','Insurance money','Other']
#Breakdown of complaints (number of relevant items / number of complaints)
claim_detail_list = [float((j.get_text())[:-1])
for i in bs.select('table.tblMod02.tblP2.mt10')
for j in i.select('td.taR')
if "%" in j.get_text()]
# claim_detail_Divide the list into 5 contents of the number of items
def list_(num):
return [claim_detail_list[i]
for i in range(len(claim_detail_list))
if i%5==(num - 1)]
#5 different lists
all_list = [list_(1),list_(2),list_(3),list_(4),list_(5)]
dataset = pd.DataFrame(all_list,
index=claim_detail,
columns=company_name_list)
#Graph creation
fig, ax = plt.subplots(figsize=(10, 8))
for i in range(len(dataset)):
ax.bar(dataset.columns, dataset.iloc[i], bottom=dataset.iloc[:i].sum())
ax.set(xlabel='Name of Life Insurance Co., Ltd.', ylabel='Breakdown of complaints')
plt.title("Breakdown of complaints")
plt.xticks(rotation=90, fontsize=12)
ax.legend(dataset.index)
plt.show()
――I would appreciate it if you could refer to it when choosing life insurance! !! ――But I want you to decide the insurance by actually looking at the HP, not just the graph! (Excuse for escape)
I created a stacked bar graph with matplotlib in Python and added a data label Complaint reception information and insurance payment information of life insurance companies
Recommended Posts