目录
彩票那点事儿
最近朋友的一个小需求突然让我有了这个小想法,这个需求也能玩一玩数据分析,当学习demo,当然我没玩过彩票,也不懂,看百度了解了一下主要是练习以下几方面。。。😂
- 脚本数据集
- 爬虫练习
- 数据处理
- 回归分析
- 描述性统计分析
代码都已上传GitHub点击查看
数据分析基本意义
– 数据分析是指用适当的统计方法对收集来的大量第一手数据(资料)和第二手数据(资料)进行分析,以求最大化地开发数据资料的功能,发挥数据的作用。是为了提取有用信息和形成结论而对数据加以详细研究和概况总结的过程。
– 在实用中,数据分析可帮助人们作出判断,以便采取适当行动。
首先讲一下数据分析的整个思路:
数据分析的步骤
确定一下目的
1、每个号码出现的次数是一样的吗?
2、往期数据能预测下一期的号码吗?
3、连号有什么规律吗?(这个暂时没做原谅我懒了😂)
数据准备
爬取往期的彩票数据,经过对比后发现这家数据完整也特别好爬,对比过重庆时时彩他居然支持直接导出数据。。。不开心。。没有爬数据的快感。。。
最后选择 http://datachart.500.com/dlt/history/history.shtml
分析页面:
- 进入f12输入0查找 查看相应规律爬取往期数据
- 对页面进一步获取html元素,分析页面组成
- python脚本 爬取历史数据
import requests
from lxml import etree
import pandas as pd
def get_ten_years_data(url):
headers={
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36'
}
response=requests.get(url, headers=headers)
if response.status_code == 200:
return response.text
return None
url="http://datachart.500.com/dlt/history/newinc/history.php?start=00001&end=19119";
# print(get_ten_years_data(url))
data = etree.HTML(get_ten_years_data(url))
# print(data)
trs = data.xpath('//tr')
k=0
for tr in trs:
k=k+1
print(k)
requests =[]
for i in range(1, k-3):
result_num = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[1]/text()')[0]
print(result_num, end='\t')
resrult_bef1 = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[2]/text()')[0]
print(resrult_bef1, end='\t')
resrult_bef2 = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[3]/text()')[0]
print(resrult_bef2, end='\t')
resrult_bef3 = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[4]/text()')[0]
print(resrult_bef3, end='\t')
resrult_bef4 = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[5]/text()')[0]
print(resrult_bef4, end='\t')
resrult_bef5 = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[6]/text()')[0]
print(resrult_bef5, end='\t')
resrult_beh1 = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[7]/text()')[0]
print(resrult_beh1, end='\t')
resrult_beh2 = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[8]/text()')[0]
print(resrult_beh2, end='\t')
prize_pool = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[9]/text()')[0]
print(prize_pool, end='\t')
first_prize_size = data.xpath('//*[@id="tdata"]/tr[' + str(i) + ']/td[10]/text()')[0]
print(first_prize_size, end='\t')
first_prize = data.xpath('//*[@id="tdata"]/tr[' + str(i) + ']/td[11]/text()')[0]
print(first_prize, end='\t')
second_prize_size = data.xpath('//*[@id="tdata"]/tr[' + str(i) + ']/td[12]/text()')[0]
print(second_prize_size, end='\t')
second_prize = data.xpath('//*[@id="tdata"]/tr[' + str(i) + ']/td[13]/text()')[0]
print(second_prize, end='\t')
total_bet_amount = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[14]/text()')[0]
print(total_bet_amount, end='\t')
result_day = data.xpath('//*[@id="tdata"]/tr['+str(i)+']/td[15]/text()')[0]
print(result_day, end='\t')
print(i)
pos ={
'result_num': result_num,
'resrult_bef1': resrult_bef1,
'resrult_bef2': resrult_bef2,
'resrult_bef3': resrult_bef3,
'resrult_bef4': resrult_bef4,
'resrult_bef5': resrult_bef5,
'resrult_beh1': resrult_beh1,
'resrult_beh2': resrult_beh2,
'prize_pool': prize_pool,
'first_prize_size': first_prize_size,
'first_prize': first_prize,
'second_prize_size': second_prize_size,
'second_prize': second_prize,
'total_bet_amount': total_bet_amount,
'result_day': result_day,
}
requests.append(pos)
# print(requests)
df = pd.DataFrame(requests)
df.to_csv('/Users/lianxiaobao/lianxiaobao/bigdatabook/daletou.csv', mode='a')
- 将数据保存到了我的superset中展示方便日后多维分析展示,该表格当然没有做处理只是
select *..
能预测下一期吗?
- 导包
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
import statsmodels.api as sm
- 概览数据
data = pd.read_csv('/Users/lianxiaobao/lianxiaobao/bigdatabook/daletou.csv')
data.head()
Unnamed: 0 | first_prize | first_prize_size | prize_pool | resrult_bef1 | resrult_bef2 | resrult_bef3 | resrult_bef4 | resrult_bef5 | resrult_beh1 | resrult_beh2 | result_day | result_num | second_prize | second_prize_size | total_bet_amount | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 10,000,000 | 4 | 2,450,995,411 | 3 | 6 | 9 | 23 | 34 | 2 | 11 | 2019/10/19 | 19119 | 611,893 | 83 | 296,906,555 |
1 | 1 | 10,000,000 | 2 | 2,505,219,109 | 2 | 3 | 13 | 19 | 26 | 2 | 3 | 2019/10/16 | 19118 | 406,469 | 101 | 272,734,633 |
2 | 2 | 10,000,000 | 4 | 2,510,705,016 | 1 | 18 | 21 | 25 | 35 | 7 | 8 | 2019/10/14 | 19117 | 806,808 | 66 | 271,077,215 |
3 | 3 | 10,000,000 | 4 | 2,540,591,129 | 2 | 10 | 16 | 21 | 23 | 2 | 12 | 2019/10/12 | 19116 | 770,679 | 87 | 297,819,968 |
4 | 4 | 10,000,000 | 6 | 2,576,114,778 | 1 | 18 | 21 | 28 | 32 | 5 | 12 | 2019/10/9 | 19115 | 498,979 | 105 | 286,493,206 |
data.columns
Index(['Unnamed: 0', 'first_prize', 'first_prize_size', 'prize_pool',
'resrult_bef1', 'resrult_bef2', 'resrult_bef3', 'resrult_bef4',
'resrult_bef5', 'resrult_beh1', 'resrult_beh2', 'result_day',
'result_num', 'second_prize', 'second_prize_size', 'total_bet_amount'],
dtype='object')
-
简单线性回归
-
模型
-
对于简单的线性回归,只考虑次数的影响。在直接进入建模之前,看一下数据的样子。
-
使用matplotlib 一个Python绘图库来制作散点图。
-
-
前区的一个球可能出现的数字和次数的散点图
plt.figure(figsize=(16, 8))
plt.scatter(
data['result_day'],
data['resrult_bef1'],
c='black'
)
plt.xlabel("daletou open day(d)")
plt.ylabel("bef1 (num)")
plt.show()
后区的一个球可能出现的数字和次数的散点图
plt.figure(figsize=(16, 8))
plt.scatter(
data['result_day'],
data['resrult_beh1'],
c='black'
)
plt.xlabel("daletou open day(d)")
plt.ylabel("bef1 (num)")
plt.show()
生成简单回归线图形方法一
- 假设次数和号码数有关联
- 生成近似函数
X = data['Unnamed: 0'].values.reshape(-1,1)
y = data['resrult_bef1'].values.reshape(-1,1)
reg = LinearRegression()
reg.fit(X, y)
print(reg.coef_[0][0])
print(reg.intercept_[0])
0.0007193466601768446
5.6506553914011715
print("The huigui model is: Y = {:.6} + {:.6}X".format(reg.intercept_[0], reg.coef_[0][0]))
The huigui model is: Y = 5.65066 + 0.000719347X
- 生成简单回归线图形
predictions = reg.predict(X)
plt.figure(figsize=(16, 8))
plt.scatter(
data['Unnamed: 0'],
data['resrult_bef1'],
c='black'
)
plt.plot(
data['Unnamed: 0'],
predictions,
c='blue',
linewidth=4
)
plt.xlabel("daletou open day(d)")
plt.ylabel("bef1 (num)")
plt.show()
生成简单回归线图形方法二
X = data['Unnamed: 0']
y = data['resrult_bef1']
X2 = sm.add_constant(X)
model = sm.OLS(y, X2)
result = model.fit()
result.params
const 5.650655
Unnamed: 0 0.000719
dtype: float64
print(result2.summary())
OLS Regression Results
==============================================================================
Dep. Variable: resrult_bef1 R-squared: 0.006
Model: OLS Adj. R-squared: 0.006
Method: Least Squares F-statistic: 11.54
Date: Thu, 24 Oct 2019 Prob (F-statistic): 0.000696
Time: 19:20:31 Log-Likelihood: -5781.4
No. Observations: 1901 AIC: 1.157e+04
Df Residuals: 1899 BIC: 1.158e+04
Df Model: 1
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 5.6507 0.232 24.319 0.000 5.195 6.106
Unnamed: 0 0.0007 0.000 3.397 0.001 0.000 0.001
==============================================================================
Omnibus: 388.306 Durbin-Watson: 2.003
Prob(Omnibus): 0.000 Jarque-Bera (JB): 695.987
Skew: 1.275 Prob(JB): 7.38e-152
Kurtosis: 4.510 Cond. No. 2.19e+03
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 2.19e+03. This might indicate that there are
strong multicollinearity or other numerical problems.
# 中间偏下的 coef 列就是计算出的回归系数。
# 我们还可以将拟合结果画出来。先调用拟合结果的 fittedvalues 得到拟合的 y 值。
y_fitted = result.fittedvalues
# 然后使用 matplotlib.pyploft 画图。首先设定图轴,图片大小为 16×8。
fig, ax = plt.subplots(figsize=(16,8))
# 画出原数据,图像为圆点,默认颜色为蓝。
ax.plot(X, y, 'o', label='data')
# 画出拟合数据,图像为红色带点间断线。
ax.plot(X, y_fitted, 'r--.',label='OLS')
# 放置注解。
ax.legend(loc='best')
生成简单回归线图形方法三
- 简单暴力直接上excle神器
1、首先你要有数据分析功能
2、开始happy
- 1
- 2
- 3
回归参数解释
OLS Regression Results
==============================================================================
Dep. Variable: resrult_bef1 R-squared: 0.006
Model: OLS Adj. R-squared: 0.006
Method: Least Squares F-statistic: 11.54
Date: Thu, 24 Oct 2019 Prob (F-statistic): 0.000696
Time: 19:20:31 Log-Likelihood: -5781.4
No. Observations: 1901 AIC: 1.157e+04
Df Residuals: 1899 BIC: 1.158e+04
Df Model: 1
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 5.6507 0.232 24.319 0.000 5.195 6.106
Unnamed: 0 0.0007 0.000 3.397 0.001 0.000 0.001
==============================================================================
Omnibus: 388.306 Durbin-Watson: 2.003
Prob(Omnibus): 0.000 Jarque-Bera (JB): 695.987
Skew: 1.275 Prob(JB): 7.38e-152
Kurtosis: 4.510 Cond. No. 2.19e+03
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 2.19e+03. This might indicate that there are
strong multicollinearity or other numerical problems.
- 左边:(模型背景描述)
- Dep.Variable: 输出变量的名称
- Model :模型名称
- Method: 方法 其中 Least Squares 表示最小二乘法
- Date: 日期
- Time: 时间
- No.Observations: 样本数目
-
Df Residuals : 残差自由度 (观测数No.Observations - (参数数目Df Model+1常数))
- –残差代表的是实际观察值与估计值的差
- Df Model: 模型参数个数,相当于输入的X的元素个数
- 右边:(模型质量描述)(需要参考判断的数据)
-
R- squared : 可决系数,用来判断估计的准确性,范围在 [0,1] 约接近1 ,说明对y的解释能力越强,拟合越好
- Adj-R- squared: 通过样本数量与模型数量对R-squared进行修正,奥卡姆剃刀原理,避免描述冗杂
- F-statistic : 衡量拟合的显著性, 重要程度。模型的均方误差除以残差的均方误差,值越大,H0 越不可能
- Prob(F-statistic): 当prob(F-statistic)<α时,表示拒绝原假设,即认为模型是显著的;
- 当prob(F-statistic)>α时,表示接受原假设,即认为模型不是显著的
- Log likelihood (对数似然比LLR) :(很多说法是值越大,说明模型拟合的较好)(但有待考察,似然比服从统计量,大于卡方临界值拒绝原假设) 通过最大似然估计参数的选取的拟合性 (Davidson 与MacKinnon(1993)年说:对于线性回归模型,不管它误差是不是正态分布,都不需要过问LM,W,LLR,因为这些信息已被F检验所含有)
- AIC: AIC可以表示为: AIC=2k-2ln(L) 其中:k是参数的数量,L是似然函数。 衡量拟合优良性,选择AIC 最小的模型, 引入了惩罚项,避免参数过多,过拟合
- BIC: 贝叶斯信息准则 BIC=kln(n)-2ln(L) ,BIC相比AIC在大数据量时对模型参数惩罚得更多,导致BIC更倾向于选择参数少的简单模型。
-
- 下半部分:(模型描述)
- coef: 系数 const表示常数项
- std err :系数估计的基本标准误差
- t : t 统计值,衡量系数统计显著程度的指标
-
P>|t| : 系数= 0的零假设为真的P值。如果它小于置信水平,通常为0.05,则表明该术语与响应之间存在统计上显着的关系。度的指标 [0.025,0.975]: 95%置信区间的下限和上限值
- Omnibus :属于一种统计测验,测试一组数据中已解释方差是否显著大于未解释方差,但omnibus不显著,模型也可能存在合法的显著影响, 比如两个变量中有一个不显著,即便另一个显著.通常用于对比
- Prob(Omnibus):将上面的统计数据变成概率
- Durbin-Watson : 残差是否符合正态分布,在2左右说明是服从正态分布的,偏离2太远,解释能力受影响 是否自相关, 受到前后影响 ,与表中上限进行比较,如果D>上限 不存在相关性 . D<下限 存在正相关性,在上下限之间,无法得出结论
- Skewness: 偏度, 关于平均值的数据对称性的度量。正态分布误差应是关于平均值对称的分布。
- Kurtosis: 峰度, 分布形状的量度,比较接近均值与远离均值的数据量 如果大于三,说明峰的形状比较陡峭,形状较尖 正态分布的峰度(系数)为常数3,均匀分布的峰度(系数)为常数1.8
- Jarque-Bera(JB) : Jarque–Bera检验是对样本数据是否具有符合正态分布的偏度和峰度的拟合优度的检验。 其统计测试结果总是非负的。如果结果远大于零,则表示数据不具有正态分布。
- Prob(JB): 上面统计量的概率形式
- Cond. No :多重共线性测试(如果多个参数,这些参数是否相互关联)
从简单线性图可以看出一个球的预测都很随机,从图中也可以看出从数据发描述性统计更能体现数据特征 想全中 太难了
每个号码出现的次数是一样的吗?
清洗数据
想要看一下近年来奖金池,押注额的变化但是发现数据还是有问题有逗号的存在
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import re
import csv
data = pd.read_csv('/Users/lianxiaobao/lianxiaobao/bigdatabook/daletou2.csv')
# data = pd.read_csv('/Users/lianxiaobao/lianxiaobao/bigdatabook/daletou2.csv' ,usecols=[3,11])
# print(data.head())
print(int(data.describe().ix[0,0]))
record_num = data.__len__()
print(record_num)
print(data.ix[0, :])
# 遍历出所有行
# for i in range(record_num):
# record = data.ix[i, :]
# # re.sub(r'[^\w\s]', '',s) 去除逗号
# print(re.sub(r'[^\w\s]', '', str(record['prize_pool'])))
# print(re.sub(r'[-]', '', str(record['result_day'])))
# 去除符号
def convert1(record):
record = re.sub(r'[^\w\s]', '', str(record))
return record
# 去除 -
def convert2(record):
record = re.sub(r'[-]', '', str(record))
return record
#建新csv文件
path = r'/Users/lianxiaobao/lianxiaobao/bigdatabook/daletou4.csv'
csvfile = open(path, 'w', encoding='utf-8')
writer = csv.writer(csvfile)
writer.writerow(('Unnamed: 0','result_num', 'resrult_bef1', 'resrult_bef2', 'resrult_bef3', 'resrult_bef4',
'resrult_bef5', 'resrult_beh1', 'resrult_beh2','prize_pool', 'first_prize_size', 'first_prize','second_prize_size',
'second_prize', 'result_day','total_bet_amount'))
for i in range(record_num):
record = data.ix[i, :]
first_prize = int(convert1(record['first_prize']))
prize_pool = int(convert1(record['prize_pool']))
second_prize = int(convert1(record['second_prize']))
# 时间类型保持不变就好 去掉-分隔符会导致py画图稀疏
# result_day = int(convert1(record['result_day']))
total_bet_amount = int(convert1(record['total_bet_amount']))
writer.writerow((record['Unnamed: 0'], record['result_num'], record['resrult_bef1'], record['resrult_bef2'],
record['resrult_bef3'], record['resrult_bef4'], record['resrult_bef5'], record['resrult_beh1'], record['resrult_beh2']
, prize_pool, record['first_prize_size'], first_prize, record['second_prize_size'], second_prize, record['result_day'],
total_bet_amount))
csvfile.close()
描述性统计分析
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
import statsmodels.api as sm
import matplotlib.ticker as ticker
data = pd.read_csv('/Users/lianxiaobao/lianxiaobao/bigdatabook/daletou4.csv')
data.head()
Unnamed: 0 | result_num | resrult_bef1 | resrult_bef2 | resrult_bef3 | resrult_bef4 | resrult_bef5 | resrult_beh1 | resrult_beh2 | prize_pool | first_prize_size | first_prize | second_prize_size | second_prize | result_day | total_bet_amount | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 19119 | 3 | 6 | 9 | 23 | 34 | 2 | 11 | 2450995411 | 4 | 10000000 | 83 | 611893 | 2019-10-19 | 296906555 |
1 | 1 | 19118 | 2 | 3 | 13 | 19 | 26 | 2 | 3 | 2505219109 | 2 | 10000000 | 101 | 406469 | 2019-10-16 | 272734633 |
2 | 2 | 19117 | 1 | 18 | 21 | 25 | 35 | 7 | 8 | 2510705016 | 4 | 10000000 | 66 | 806808 | 2019-10-14 | 271077215 |
3 | 3 | 19116 | 2 | 10 | 16 | 21 | 23 | 2 | 12 | 2540591129 | 4 | 10000000 | 87 | 770679 | 2019-10-12 | 297819968 |
4 | 4 | 19115 | 1 | 18 | 21 | 28 | 32 | 5 | 12 | 2576114778 | 6 | 10000000 | 105 | 498979 | 2019-10-09 | 286493206 |
- 输出整体数据描述
data.describe()
Unnamed: 0 | result_num | resrult_bef1 | resrult_bef2 | resrult_bef3 | resrult_bef4 | resrult_bef5 | resrult_beh1 | resrult_beh2 | prize_pool | first_prize_size | first_prize | second_prize_size | second_prize | total_bet_amount | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
count | 1901.000000 | 1901.000000 | 1901.000000 | 1901.000000 | 1901.000000 | 1901.000000 | 1901.000000 | 1901.000000 | 1901.000000 | 1.901000e+03 | 1901.000000 | 1.901000e+03 | 1901.000000 | 1.901000e+03 | 1.901000e+03 |
mean | 950.000000 | 13157.299316 | 6.334035 | 12.648606 | 19.103104 | 24.941610 | 30.576013 | 4.403472 | 8.760126 | 1.596303e+09 | 2.720147 | 6.047543e+06 | 56.155708 | 2.142114e+05 | 1.307569e+08 |
std | 548.915749 | 3592.956887 | 5.081384 | 6.333922 | 6.561362 | 6.014566 | 4.401332 | 2.707255 | 2.674698 | 2.090622e+09 | 5.143986 | 4.034354e+06 | 82.276709 | 2.759933e+05 | 7.284895e+07 |
min | 0.000000 | 7001.000000 | 1.000000 | 2.000000 | 3.000000 | 4.000000 | 12.000000 | 1.000000 | 2.000000 | 0.000000e+00 | 0.000000 | 0.000000e+00 | 1.000000 | 3.000000e+03 | 1.579569e+07 |
25% | 475.000000 | 10076.000000 | 2.000000 | 8.000000 | 14.000000 | 21.000000 | 29.000000 | 2.000000 | 7.000000 | 1.030280e+08 | 0.000000 | 0.000000e+00 | 22.000000 | 8.726500e+04 | 6.274881e+07 |
50% | 950.000000 | 13090.000000 | 5.000000 | 12.000000 | 19.000000 | 26.000000 | 32.000000 | 4.000000 | 9.000000 | 2.883201e+08 | 1.000000 | 6.993911e+06 | 40.000000 | 1.524690e+05 | 1.088826e+08 |
75% | 1425.000000 | 16105.000000 | 9.000000 | 17.000000 | 24.000000 | 30.000000 | 34.000000 | 6.000000 | 11.000000 | 3.252308e+09 | 3.000000 | 1.000000e+07 | 68.000000 | 2.359460e+05 | 1.951219e+08 |
max | 1900.000000 | 19119.000000 | 30.000000 | 32.000000 | 33.000000 | 34.000000 | 35.000000 | 11.000000 | 12.000000 | 7.368392e+09 | 106.000000 | 2.056120e+07 | 2251.000000 | 5.000000e+06 | 3.172321e+08 |
- 大家对双色球的热情是什么样的呢?
# plt.figure(figsize=(16, 8))
# plt.plot(
# data['result_day'],
# data['prize_pool'],
# c='blue',
# linewidth=2
# )
# plt.xlabel("history years(year)")
# plt.ylabel("prize_pool (Billion)")
# plt.show()
# 修改横坐标刻度密度的方法 1
# 通过修改tick_spacing的值可以修改x轴的密度
# fig, ax = plt.subplots(1,1)
# ax.plot(data['result_day'],data['prize_pool'])
# ax.xaxis.set_major_locator(ticker.MultipleLocator(10000))
# plt.xlabel("history years(year)")
# plt.ylabel("prize_pool (Billion)")
# plt.show()
# 修改横坐标刻度密度的方法 2
plt.figure(figsize=(16, 8))
plt.plot(
data['result_day'],
data['prize_pool'],
c='blue',
linewidth=2
)
plt.xlabel("history years(year)")
plt.ylabel("prize_pool (Billion)")
x_major_locator=MultipleLocator(200)
#把x轴的刻度间隔设置为10000,并存在变量里
y_major_locator=MultipleLocator(500000000)
#把y轴的刻度间隔设置为500000000,并存在变量里
ax=plt.gca()
#ax为两条坐标轴的实例
#x_major_locator.MAXTICKS = 1500
ax.xaxis.set_major_locator(x_major_locator)
#把x轴的主刻度设置为1的倍数
ax.yaxis.set_major_locator(y_major_locator)
#把y轴的主刻度设置为10的倍数
#plt.xlim(-0.5,11)
#把x轴的刻度范围设置为-0.5到11,因为0.5不满一个刻度间隔,所以数字不会显示出来,但是能看到一点空白
#plt.ylim(-5,110)
#把y轴的刻度范围设置为-5到110,同理,-5不会标出来,但是能看到一点空白
plt.show()
19年这个趋势是什么鬼造成的呢?
彩民们在14年以后买彩票的热情逐渐提升一直疯狂到2018年底近75亿,但是进入2019年直线下降,难道是和我一样被🏠?
- 派发的奖金这些年怎么变化的呢?
plt.figure(figsize=(16, 8))
plt.plot(
data['result_day'],
data['total_bet_amount'],
c='blue',
linewidth=2
)
plt.xlabel("history years(year)")
plt.ylabel("total_bet_amount (Billion)")
x_major_locator=MultipleLocator(200)
y_major_locator=MultipleLocator(50000000)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.show()
对我们越来约好了,派发额一年比一年更高基本呈直线匀速增长至30亿左右
- 一等奖奖金又是怎样的呢?
plt.figure(figsize=(16, 8))
plt.scatter(
data['result_day'],
data['first_prize'],
c='green'
)
plt.xlabel("history years(year)")
plt.ylabel("first_prize (Ten million
)")
x_major_locator=MultipleLocator(200)
y_major_locator=MultipleLocator(5000000)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.show()
好稳定啊 基本在500-1000万之间 超大奖很少
- 每个区各个球号出现的概率是怎样的呢?
# 对该列做group by 分析每个号出现的次数 count
resrult_bef1 = data.groupby('resrult_bef1').size()
type(resrult_bef1) # Series
resrult_bef1.index
Int64Index([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30],
dtype='int64', name='resrult_bef1')
resrult_bef1.values
array([277, 211, 226, 156, 165, 144, 129, 87, 77, 77, 60, 51, 42,
46, 30, 27, 13, 16, 17, 12, 14, 8, 5, 4, 1, 2,
1, 2, 1])
resrult_bef1
resrult_bef1
1 277
2 211
3 226
4 156
5 165
6 144
7 129
8 87
9 77
10 77
11 60
12 51
13 42
14 46
15 30
16 27
17 13
18 16
19 17
20 12
21 14
22 8
23 5
24 4
25 1
26 2
27 1
29 2
30 1
dtype: int64
fig, axes = plt.subplots(1, 1)
bef1 = pd.Series(resrult_bef1)
bef1.plot.bar(ax=axes, color='green', alpha=0.8,figsize=(16,8))
# data.plot.barh(ax=axes[1], color='k', alpha=0.7)
前区1:
data = pd.read_csv('/Users/lianxiaobao/lianxiaobao/bigdatabook/daletou4.csv')
resrult_bef2 = data.groupby('resrult_bef2').size()
fig, axes = plt.subplots(1, 1)
bef2 = pd.Series(resrult_bef2)
bef2.plot.bar(ax=axes, color='green', alpha=0.8,figsize=(16,8))
前区2:
- 就不再一一举例最后7个区统计结果为
总结一下:
中大奖真的幸福,太难了