嗨喽,大家好呀~这里是爱看美女的茜茜呐
又到了学Python时刻~
找从19年到现在的开奖历史数据,我们首先要把这个历史数据拿到,
拿到我们再进行做分析,分析每个号码出现的频率是多少,
哪个多,我们就买哪个,哪个概率高就买哪个(仅供娱乐)
本次不讲如何采集,所以数据是现成的
我的开发环境是 anaconda --> jupyter notebook
导入模块
import numpy as np
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Pie
整理数据
df = pd.read_csv('彩票数据集.csv',header=None,index_col=0)
df
总体分析
把红球的号码拿出来
列:从1到6拿到数据
行: 所有行的数据都是想要的数据
red_ball = df.loc[:,1:6]
把蓝球的号码拿出来
blue_ball = df.loc[:,7]
做数据统计
每个号码出现的次数
flatten是numpy.ndarray.flatten的一个函数,即返回一个折叠成一维的数组。
red_ball_count = pd.value_counts(red_ball.values.flatten())
blue_ball_count = pd.value_counts(blue_ball)
x = red_ball_count.index.tolist()
y = red_ball_count.values.tolist()
可视化展示
pie = (
Pie()
.add(""
,[list(z) for z in zip(x, y)]
)
)
pie.render_notebook()
x = blue_ball_count.index.tolist()
y = blue_ball_count.values.tolist()
pie = (
Pie()
.add(""
,[list(z) for z in zip(x, y)]
)
)
pie.render_notebook()
19年
df_19 = df.loc[19151:19001,:]
red_ball = df_19.loc[:,1:6]
把蓝球的号码拿出来
blue_ball = df_19.loc[:,7]
做数据统计
每个号码出现的次数
red_ball_count = pd.value_counts(red_ball.values.flatten())
blue_ball_count = pd.value_counts(blue_ball)
x = red_ball_count.index.tolist()
y = red_ball_count.values.tolist()
pie = (
Pie()
.add(""
,[list(z) for z in zip(x, y)]
)
)
pie.render_notebook()
x = blue_ball_count.index.tolist()
y = blue_ball_count.values.tolist()
pie = (
Pie()
.add(""
,[list(z) for z in zip(x, y)]
)
)
pie.render_notebook()
20年
df_20 = df.loc[19151:19001,:]
red_ball = df_20.loc[:,1:6]
把蓝球的号码拿出来
blue_ball = df_20.loc[:,7]
做数据统计
每个号码出现的次数
red_ball_count = pd.value_counts(red_ball.values.flatten())
blue_ball_count = pd.value_counts(blue_ball)
x = red_ball_count.index.tolist()
y = red_ball_count.values.tolist()
pie = (
Pie()
.add(""
,[list(z) for z in zip(x, y)]
)
)
pie.render_notebook()
x = blue_ball_count.index.tolist()
y = blue_ball_count.values.tolist()
pie = (
Pie()
.add(""
,[list(z) for z in zip(x, y)]
)
)
pie.render_notebook()
21年
df_21 = df.loc[21073:21001,:]
red_ball = df_21.loc[:,1:6]
# 把蓝球的号码拿出来
blue_ball = df_21.loc[:,7]
# 做数据统计
# 每个号码出现的次数
red_ball_count = pd.value_counts(red_ball.values.flatten())
blue_ball_count = pd.value_counts(blue_ball)
x = red_ball_count.index.tolist()
y = red_ball_count.values.tolist()
pie = (
Pie()
.add(""
,[list(z) for z in zip(x, y)]
)
)
pie.render_notebook()
x = blue_ball_count.index.tolist()
y = blue_ball_count.values.tolist()
pie = (
Pie()
.add(""
,[list(z) for z in zip(x, y)]
)
)
pie.render_notebook()
感谢你观看我的文章呐~本次航班到这里就结束啦
希望本篇文章有对你带来帮助 ,有学习到一点知识~
躲起来的星星也在努力发光,你也要努力加油(让我们一起努力叭)。
最后,宣传一下呀~更多源码、资料、素材、解答、交流皆点击下方名片获取呀