!pip install lxml
import pandas as pd
import io
import requests
url = 'http://www.japannetbank.co.jp/lottery/co/minilotojnb.csv'
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).content
df = pd.read_csv(io.StringIO(r.decode('cp932')), index_col=0)
df.sort_index(inplace=True)
df.head()
df.dtypes
dfl = df.iloc[:, 2:8]
dfl.head()
sel = dfl.melt()
sel.head()
ptl = pd.pivot_table(sel, index='value', aggfunc='count')
ptl
ptl.columns = ['frequency']
ptl.sort_values('frequency', ascending=False).plot.bar()
ser = sel.replace('抽せん数字\d$', '抽せん数字', regex=True)
ser
ptr = ser.pivot_table(values='value', index='value', columns='variable', aggfunc=lambda x : len(x), fill_value = 0)
ptr['合計'] = ptr['抽せん数字'] + ptr['ボーナス数字']
ptr
ptr.sort_values('合計', ascending=False).plot.bar(y=['抽せん数字', 'ボーナス数字'], stacked=True)
- 抽せん数字とボーナス数字の度数分布の積上棒グラフが作りたい