0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Python]生命保険会社の苦情件数を偏差値でグラフにしてみた。

Last updated at Posted at 2020-12-11

概要

苦情件数の偏差値を棒グラフで表現

棒グラフ

hensati.png

コード

from bs4 import BeautifulSoup
import urllib.request as req
import re
import matplotlib.pyplot as plt
import numpy as np


url = "https://www.seiho.or.jp/member/complaint/"
res = req.urlopen(url) 
bs = BeautifulSoup(res, "html.parser") 

# 苦情件数の偏差値を棒グラフで表現

# 保険会社の名前
# 名前が長いので「生命保険株式会社」を消す
company_name_list = [re.sub('生命保険株式会社','',i.get_text().replace('\n','') )
                      for i in bs.select('div.headMod04.mt30')]
# 会社に寄せられた苦情件数(件)
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')]
# 個人保険保有契約件数(件)
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]

# 苦情の割合(%)
claim_rate_list = [(i/j) * 100 for i,j in zip(claim_count_list,guest_number_list)]


# ここからは新しく追加したコード
def func_print_deviation_value(data):
    ave = np.average(data)
    std = np.std(data)
    deviation_value_list = [int((i - ave) / std * 10 + 50) for i in data]
    return deviation_value_list

# 苦情の偏差値
deviation_value_list = func_print_deviation_value(claim_rate_list)


plt.title("苦情の偏差値")  
plt.xlabel('生命保険株式会社の名前')
plt.ylabel('偏差値')
plt.xticks(rotation=90, fontsize=8)
plt.bar(company_name_list,deviation_value_list)
plt.show()

苦情件数の偏差値を棒グラフで表現(大きい順にソート)

棒グラフ

hensati_big.png

コード

from bs4 import BeautifulSoup
import urllib.request as req
import re
import matplotlib.pyplot as plt
import numpy as np


url = "https://www.seiho.or.jp/member/complaint/"
res = req.urlopen(url) 
bs = BeautifulSoup(res, "html.parser") 

# 苦情件数の偏差値を棒グラフで表現(大きい順にソート)

# 保険会社の名前
# 名前が長いので「生命保険株式会社」を消す
company_name_list = [re.sub('生命保険株式会社','',i.get_text().replace('\n','') )
                      for i in bs.select('div.headMod04.mt30')]
# 会社に寄せられた苦情件数(件)
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')]
# 個人保険保有契約件数(件)
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]

# 苦情の割合(%)
claim_rate_list = [(i/j) * 100 for i,j in zip(claim_count_list,guest_number_list)]


# ここからは新しく追加したコード
def func_print_deviation_value(data):
    ave = np.average(data)
    std = np.std(data)
    deviation_value_list = [int((i - ave) / std * 10 + 50) for i in data]
    return deviation_value_list

# 苦情の偏差値
deviation_value_list = func_print_deviation_value(claim_rate_list)

company_deviation_list = [[i,j] for i,j in zip(company_name_list,deviation_value_list)]

company_deviation_list.sort(key=lambda x: x[1],reverse=True) 

# 保険会社の名前、苦情偏差値のリストを更新
deviation_value_list = [i[1] for i in company_deviation_list]
company_name_list = [i[0] for i in company_deviation_list]

plt.title("苦情の偏差値")  
plt.xlabel('生命保険株式会社の名前')
plt.ylabel('偏差値')
plt.xticks(rotation=90, fontsize=8)
plt.bar(company_name_list,deviation_value_list)
plt.show()

まとめ

  • 苦情の多い保険会社を可視化できた。
  • 偏差値80ってもはや東大レベル。。。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?