Python數(shù)據(jù)分析之雙色球中藍紅球分析統(tǒng)計示例
本文實例講述了Python數(shù)據(jù)分析之雙色球中藍紅球分析統(tǒng)計。分享給大家供大家參考,具體如下:
這里接著上一篇Python數(shù)據(jù)分析之獲取雙色球歷史信息收集的數(shù)據(jù)處理下,
newdata.txt數(shù)據(jù)樣子
...
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
...
一、藍球統(tǒng)計:
analyze_data_lan.py
#!/usr/bin/python # -*- coding:UTF-8 -*- #調(diào)用pandas numpy matplotlib包 import pandas as pd import numpy as np import matplotlib.pyplot as plt #讀取newdata.txt文件 df = pd.read_table('newdata.txt',header=None,sep=',') # print df # print df[1:3] #第2到第3行(索引0開始為第一行,1代表第二行,不包含第四行) # print df.loc[0:10,:] #第1行到第9行的全部列 # print df.loc[:,[0,7]] #全部行的第1和第8列 tdate = sorted(df.loc[:,0]) #取第一列數(shù)據(jù) # print tdate tdate1 = [] #將tdate數(shù)據(jù)讀取到列表中 for i in tdate: tdate1.append(i) print tdate1 # s = pd.Series(tdate1, index=tdate1) s = pd.Series(range(1,len(tdate1)+1), index=tdate1) #將日期轉(zhuǎn)換為對應的數(shù)值從1開始 # print s tblue = list(reversed(df.loc[:,7])) #對數(shù)據(jù)取反 print tblue fenzu = pd.value_counts(tblue,ascending=False) #將數(shù)據(jù)進行分組統(tǒng)計,按照統(tǒng)計數(shù)降序排序 print fenzu x=list(fenzu.index[:]) #獲取藍色號碼 y=list(fenzu.values[:]) #獲得藍色統(tǒng)計數(shù)量 print x print y # print type(fenzu) plt.figure(figsize=(10,6),dpi=70) #配置畫圖大小、和細度 plt.legend(loc='best') # plt.plot(fenzu,color='red') #線圖 plt.bar(x,y,alpha=.5, color='b',width=0.8) #直方圖參數(shù)設置 plt.title('The blue ball number') #標題 plt.xlabel('blue number') #x軸內(nèi)容 plt.ylabel('times') #y軸內(nèi)容 plt.show() #顯示圖
結(jié)果輸出:
看來藍球9選中最多
二、紅球統(tǒng)計
analyze_data_hong.py
#!/usr/bin/python # -*- coding:UTF-8 -*- import pandas as pd import numpy as np import matplotlib.pyplot as plt #讀取文件 df = pd.read_table('newdata.txt',header=None,sep=',') # print df # print df[1:3] # print df.loc[0:10,:] # print df.loc[:,1:6] tdate = sorted(df.loc[:,0]) # print tdate h1 = df.loc[:,1] h2 = df.loc[:,2] h3 = df.loc[:,3] h4 = df.loc[:,4] h5 = df.loc[:,5] h6 = df.loc[:,6] #將數(shù)據(jù)合并到一起 all = h1.append(h2).append(h3).append(h4).append(h5).append(h6) alldata = list(all) print len(alldata) fenzu = pd.value_counts(all,ascending=False) print fenzu x=list(fenzu.index[:]) y=list(fenzu.values[:]) print x print y # print type(fenzu) plt.figure(figsize=(10,6),dpi=70) plt.legend(loc='best',) # plt.plot(fenzu,color='red') plt.bar(x,y,alpha=.5, color='r',width=0.8) plt.title('The red ball number') plt.xlabel('red number') plt.ylabel('times') plt.show()
結(jié)果輸出:
紅球1、7、14、17、26選中幾率高些
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)學運算技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python編碼操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設計有所幫助。
- 基于Python數(shù)據(jù)分析之pandas統(tǒng)計分析
- python實現(xiàn)的分析并統(tǒng)計nginx日志數(shù)據(jù)功能示例
- Python數(shù)據(jù)可視化 pyecharts實現(xiàn)各種統(tǒng)計圖表過程詳解
- Python實現(xiàn)Mysql數(shù)據(jù)統(tǒng)計及numpy統(tǒng)計函數(shù)
- python-itchat 統(tǒng)計微信群、好友數(shù)量,及原始消息數(shù)據(jù)的實例
- Python如何獲得百度統(tǒng)計API的數(shù)據(jù)并發(fā)送郵件示例代碼
- Python數(shù)據(jù)分析之雙色球統(tǒng)計兩個紅和藍球哪組合比例高的方法
- Python數(shù)據(jù)分析之雙色球統(tǒng)計單個紅和藍球哪個比例高的方法
- Python實現(xiàn)讀寫sqlite3數(shù)據(jù)庫并將統(tǒng)計數(shù)據(jù)寫入Excel的方法示例
- 用python實現(xiàn)簡單EXCEL數(shù)據(jù)統(tǒng)計的實例
- Python 數(shù)據(jù)的累加與統(tǒng)計的示例代碼
相關(guān)文章
詳解Selenium+PhantomJS+python簡單實現(xiàn)爬蟲的功能
這篇文章主要介紹了詳解Selenium+PhantomJS+python簡單實現(xiàn)爬蟲的功能,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07Python入門教程(二十)Python的Lambda表達式
這篇文章主要介紹了Python入門教程(二十)Python的Lambda表達式,lambda表達式是一行的函數(shù)。它們在其他語言中也被稱為匿名函數(shù),lambda表達式非常有用,可以讓代碼簡單,簡潔,需要的朋友可以參考下2023-04-04python皮爾遜相關(guān)性數(shù)據(jù)分析分析及實例代碼
這篇文章主要為大家介紹了python皮爾遜相關(guān)性分析及實例代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-02-02OpenCV-DFT最優(yōu)尺寸cv::getOptimalDFTSize的設置
本文主要介紹了OpenCV-DFT最優(yōu)尺寸cv::getOptimalDFTSize的設置,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-09-09如何利用Python+OpenCV實現(xiàn)簡易圖像邊緣輪廓檢測(零基礎)
輪廓是形狀分析和物體檢測和識別的有用工具,下面這篇文章主要給大家介紹了關(guān)于如何利用Python+OpenCV實現(xiàn)簡易圖像邊緣輪廓檢測(零基礎)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-05-05