Python數(shù)據(jù)分析之雙色球中藍(lán)紅球分析統(tǒng)計(jì)示例
本文實(shí)例講述了Python數(shù)據(jù)分析之雙色球中藍(lán)紅球分析統(tǒng)計(jì)。分享給大家供大家參考,具體如下:
這里接著上一篇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
...
一、藍(lán)球統(tǒng)計(jì):
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開(kāi)始為第一行,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)換為對(duì)應(yīng)的數(shù)值從1開(kāi)始 # print s tblue = list(reversed(df.loc[:,7])) #對(duì)數(shù)據(jù)取反 print tblue fenzu = pd.value_counts(tblue,ascending=False) #將數(shù)據(jù)進(jìn)行分組統(tǒng)計(jì),按照統(tǒng)計(jì)數(shù)降序排序 print fenzu x=list(fenzu.index[:]) #獲取藍(lán)色號(hào)碼 y=list(fenzu.values[:]) #獲得藍(lán)色統(tǒng)計(jì)數(shù)量 print x print y # print type(fenzu) plt.figure(figsize=(10,6),dpi=70) #配置畫(huà)圖大小、和細(xì)度 plt.legend(loc='best') # plt.plot(fenzu,color='red') #線圖 plt.bar(x,y,alpha=.5, color='b',width=0.8) #直方圖參數(shù)設(shè)置 plt.title('The blue ball number') #標(biāo)題 plt.xlabel('blue number') #x軸內(nèi)容 plt.ylabel('times') #y軸內(nèi)容 plt.show() #顯示圖
結(jié)果輸出:
看來(lái)藍(lán)球9選中最多
二、紅球統(tǒng)計(jì)
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)容感興趣的讀者可查看本站專(zhuān)題:《Python數(shù)學(xué)運(yùn)算技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python編碼操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python入門(mén)與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
- 基于Python數(shù)據(jù)分析之pandas統(tǒng)計(jì)分析
- python實(shí)現(xiàn)的分析并統(tǒng)計(jì)nginx日志數(shù)據(jù)功能示例
- Python數(shù)據(jù)可視化 pyecharts實(shí)現(xiàn)各種統(tǒng)計(jì)圖表過(guò)程詳解
- Python實(shí)現(xiàn)Mysql數(shù)據(jù)統(tǒng)計(jì)及numpy統(tǒng)計(jì)函數(shù)
- python-itchat 統(tǒng)計(jì)微信群、好友數(shù)量,及原始消息數(shù)據(jù)的實(shí)例
- Python如何獲得百度統(tǒng)計(jì)API的數(shù)據(jù)并發(fā)送郵件示例代碼
- Python數(shù)據(jù)分析之雙色球統(tǒng)計(jì)兩個(gè)紅和藍(lán)球哪組合比例高的方法
- Python數(shù)據(jù)分析之雙色球統(tǒng)計(jì)單個(gè)紅和藍(lán)球哪個(gè)比例高的方法
- Python實(shí)現(xiàn)讀寫(xiě)sqlite3數(shù)據(jù)庫(kù)并將統(tǒng)計(jì)數(shù)據(jù)寫(xiě)入Excel的方法示例
- 用python實(shí)現(xiàn)簡(jiǎn)單EXCEL數(shù)據(jù)統(tǒng)計(jì)的實(shí)例
- Python 數(shù)據(jù)的累加與統(tǒng)計(jì)的示例代碼
相關(guān)文章
詳解Selenium+PhantomJS+python簡(jiǎn)單實(shí)現(xiàn)爬蟲(chóng)的功能
這篇文章主要介紹了詳解Selenium+PhantomJS+python簡(jiǎn)單實(shí)現(xiàn)爬蟲(chóng)的功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07python?tkinter實(shí)現(xiàn)彈窗的輸入輸出
這篇文章主要為大家詳細(xì)介紹了python?tkinter實(shí)現(xiàn)彈窗的輸入輸出,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02對(duì)python過(guò)濾器和lambda函數(shù)的用法詳解
今天小編就為大家分享一篇對(duì)python過(guò)濾器和lambda函數(shù)的用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-01-01Python入門(mén)教程(二十)Python的Lambda表達(dá)式
這篇文章主要介紹了Python入門(mén)教程(二十)Python的Lambda表達(dá)式,lambda表達(dá)式是一行的函數(shù)。它們?cè)谄渌Z(yǔ)言中也被稱(chēng)為匿名函數(shù),lambda表達(dá)式非常有用,可以讓代碼簡(jiǎn)單,簡(jiǎn)潔,需要的朋友可以參考下2023-04-04python皮爾遜相關(guān)性數(shù)據(jù)分析分析及實(shí)例代碼
這篇文章主要為大家介紹了python皮爾遜相關(guān)性分析及實(shí)例代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02OpenCV-DFT最優(yōu)尺寸cv::getOptimalDFTSize的設(shè)置
本文主要介紹了OpenCV-DFT最優(yōu)尺寸cv::getOptimalDFTSize的設(shè)置,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09如何利用Python+OpenCV實(shí)現(xiàn)簡(jiǎn)易圖像邊緣輪廓檢測(cè)(零基礎(chǔ))
輪廓是形狀分析和物體檢測(cè)和識(shí)別的有用工具,下面這篇文章主要給大家介紹了關(guān)于如何利用Python+OpenCV實(shí)現(xiàn)簡(jiǎn)易圖像邊緣輪廓檢測(cè)(零基礎(chǔ))的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05