• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python数据分析之双色球统计两个红和蓝球哪组合比例高的方法

python 搞代码 4年前 (2022-01-07) 21次浏览 已收录 0个评论

这篇文章主要介绍了Python数据分析之双色球统计两个红和蓝球哪组合比例高的方法,涉及Python数值运算及图形绘制相关操作技巧,需要的朋友可以来源gaodai#ma#com搞@代~码网参考下

本文实例讲述了Python数据分析之双色球统计两个红和蓝球哪组合比例高的方法。分享给大家供大家参考,具体如下:

统计两个红球和蓝球,哪个组合最多,显示前19组数据

 #!/usr/bin/python # -*- coding:UTF-8 -*- import pandas as pd import numpy as np import matplotlib.pyplot as plt import operator #导入数据 df = pd.read_table('newdata.txt',header=None,sep=',') tdate = sorted(df.loc[:,0]) # print tdate #第1、2列的红球 h1 = df.loc[:,1:2].values # print h1 #第2、3列的红球 h2 = df.loc[:,2:3].values #第3、4列的红球 h3 = df.loc[:,3:4].values #第4、5列的红球 h4 = df.loc[:,4:5].values #第5、6列的红球 h5 = df.loc[:,5:6].values #蓝球 b1 = df.loc[:,7:7].values # print b1 #第1、3列红球 h6 = df.loc[:,1:3:2].values h7 = df.loc[:,1:4:3].values h8 = df.loc[:,1:5:4].values h9 = df.loc[:,1:6:5].values h10 = df.loc[:,2:4:2].values h11 = df.loc[:,2:5:3].values h12 = df.loc[:,2:6:4].values h13 = df.loc[:,3:5:2].values h14 = df.loc[:,3:6:3].values #第4、6列红球 h15 = df.loc[:,4:6:2].values #将蓝球添加到各红球组中(有2列数据变为3列数据),之后将所有数据按列向合并 data2 = np.append(h1, b1, axis=1) for i in [h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14,h15]: data1 = np.append(i, b1, axis=1) data2 = np.append(data2, data1, axis=0) print data2 data1 = pd.DataFrame(data2) #写入到2hldata.csv文件中 data1.to_csv('2hldata.csv',index=None,header=None) #读取文件,进行统计,并且从大倒小排序 f = open("2hldata.csv") count_dict = {} for line in f.readlines(): line = line.strip() count = count_dict.setdefault(line, 0) count += 1 count_dict[line] = count sorted_count_dict = sorted(count_dict.iteritems(), key=operator.itemgetter(1), reverse=True) # for item in sorted_count_dict: #   print "%s,%d" % (item[0], item[1]) #重置DataFrame的index fenzu = pd.DataFrame(sorted_count_dict).set_index([0]) print fenzu x = list(fenzu.index[:19]) y = list(fenzu.values[:19]) print x print y #将index替换成数值,便于画图使用 s = pd.Series(range(1,len(x)+1), index=x) plt.figure(figsize=(12,8),dpi=80) plt.legend(loc='best') plt.bar(s,y,alpha=.5, color='r',width=0.8) plt.title('The two red and one blue ball number') plt.xlabel('two red and one blue number') plt.ylabel('times') #将原来index的内容显示出来 plt.xticks(s,x, rotation=30,size=10,ha='left') plt.show() 

显示结果:

可以看出红球20、26和蓝球9以及红球17、21和蓝球14,出现次数最多12次

后期的3红球和蓝球,4红球和蓝球,5红球和蓝球,6红球和蓝球的统计,基本思路一致。

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python数学运算技巧总结》、《Python字符串操作技巧汇总》、《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

以上就是Python数据分析之双色球统计两个红和蓝球哪组合比例高的方法的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python数据分析之双色球统计两个红和蓝球哪组合比例高的方法

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址