Python双色球数据分析(2):双色球中蓝红球分析统计

  • A+
所属分类:Python 数据分析

将上一篇收集的数据处理下,newdata.txt数据样子

...

2005-08-21, 05,10,23,27,28,30,15

2005-08-18, 04,05,17,18,26,33,04

2005-08-16, 09,12,18,21,28,29,05

...

一、蓝球统计

analyze_data_lan.py

  1. #!/usr/bin/python
  2. # -*- coding:UTF-8 -*-
  3. #调用pandas numpy matplotlib包
  4. import pandas as pd
  5. import numpy as np
  6. import matplotlib.pyplot as plt
  7. #读取newdata.txt文件
  8. df = pd.read_table('newdata.txt',header=None,sep=',')
  9. # print df
  10. # print df[1:3]    #第2到第3行(索引0开始为第一行,1代表第二行,不包含第四行)
  11. # print df.loc[0:10,:]    #第1行到第9行的全部列
  12. # print df.loc[:,[0,7]]  #全部行的第1和第8列
  13. tdate = sorted(df.loc[:,0])     #取第一列数据
  14. # print tdate
  15. tdate1 = []    #将tdate数据读取到列表中
  16. for i in tdate:
  17.     tdate1.append(i)
  18. print tdate1
  19. # s = pd.Series(tdate1, index=tdate1)
  20. s = pd.Series(range(1,len(tdate1)+1), index=tdate1)    #将日期转换为对应的数值从1开始
  21. # print s
  22. tblue = list(reversed(df.loc[:,7]))    #对数据取反
  23. print tblue
  24. fenzu = pd.value_counts(tblue,ascending=False)    #将数据进行分组统计,按照统计数降序排序
  25. print fenzu
  26. x=list(fenzu.index[:])    #获取蓝色号码
  27. y=list(fenzu.values[:])    #获得蓝色统计数量
  28. print x
  29. print y
  30. # print type(fenzu)
  31. plt.figure(figsize=(10,6),dpi=70)    #配置画图大小、和细度
  32. plt.legend(loc='best')
  33. # plt.plot(fenzu,color='red')    #线图
  34. plt.bar(x,y,alpha=.5, color='b',width=0.8)    #直方图参数设置
  35. plt.title('The blue ball number')    #标题
  36. plt.xlabel('blue number')    #x轴内容
  37. plt.ylabel('times')    #y轴内容
  38. plt.show()    #显示图

结果输出:
Python双色球数据分析(2):双色球中蓝红球分析统计

看来蓝球9选中最多

二、红球统计

analyze_data_hong.py

  1. #!/usr/bin/python
  2. # -*- coding:UTF-8 -*-
  3. import pandas as pd
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6. #读取文件
  7. df = pd.read_table('newdata.txt',header=None,sep=',')
  8. # print df
  9. # print df[1:3]
  10. # print df.loc[0:10,:]
  11. # print df.loc[:,1:6]
  12. tdate = sorted(df.loc[:,0])
  13. # print tdate
  14. h1 = df.loc[:,1]
  15. h2 = df.loc[:,2]
  16. h3 = df.loc[:,3]
  17. h4 = df.loc[:,4]
  18. h5 = df.loc[:,5]
  19. h6 = df.loc[:,6]
  20. #将数据合并到一起
  21. all = h1.append(h2).append(h3).append(h4).append(h5).append(h6)
  22. alldata = list(all)
  23. print len(alldata)
  24. fenzu = pd.value_counts(all,ascending=False)
  25. print fenzu
  26. x=list(fenzu.index[:])
  27. y=list(fenzu.values[:])
  28. print x
  29. print y
  30. # print type(fenzu)
  31. plt.figure(figsize=(10,6),dpi=70)
  32. plt.legend(loc='best',)
  33. # plt.plot(fenzu,color='red')
  34. plt.bar(x,y,alpha=.5, color='r',width=0.8)
  35. plt.title('The red ball number')
  36. plt.xlabel('red number')
  37. plt.ylabel('times')
  38. plt.show()

结果输出:

Python双色球数据分析(2):双色球中蓝红球分析统计

红球1、7、14、17、26选中几率高些

深入浅出数据分析(中文版)
中国大数据生态图谱&大数据交易市场专题研究报告
Excel数据可视化分析方法大全
R语言神经网络模型银行客户信用评估数据

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: