十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這篇文章將為大家詳細(xì)講解有關(guān)Python數(shù)據(jù)分析之如何實(shí)現(xiàn)雙色球統(tǒng)計(jì)單個(gè)紅和藍(lán)球哪個(gè)比例高,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
統(tǒng)計(jì)單個(gè)紅球和藍(lán)球,哪個(gè)組合最多,顯示前19組數(shù)據(jù)
#!/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 h2 = df.loc[:,1:7:6].values #取第一列紅球和藍(lán)球 # print h2 h3 = df.loc[:,2:7:5].values #取第二列紅球和藍(lán)球 h4 = df.loc[:,3:7:4].values h5 = df.loc[:,4:7:3].values h6 = df.loc[:,5:7:2].values h7 = df.loc[:,6:7:1].values # tblue = df.loc[:,7] #將上方切分的所有數(shù)據(jù)組合到一起 data = np.append(h2, h3, axis = 0) data = np.append(data, h4, axis = 0) data = np.append(data, h5, axis = 0) data = np.append(data, h6, axis = 0) data = np.append(data, h7, axis = 0) # print data data1 = pd.DataFrame(data) # print data1 #寫入到一個(gè)文件中 data1.to_csv('hldata.csv',index=None,header=None) #讀取文件,將組合進(jìn)行統(tǒng)計(jì)并從大到小排序 f = open("hldata.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]) # print sorted_count_dict fenzu = pd.DataFrame(sorted_count_dict).set_index([0]) #print fenzu #分別從第一列和第二列取前19個(gè)數(shù)據(jù)放到x y中 x = list(fenzu.index[:19]) y = list(fenzu.values[:19]) print x print y #將x對(duì)應(yīng)數(shù)值,不然畫圖報(bào)錯(cuò) s = pd.Series(range(1,len(x)+1), index=x) #設(shè)置畫圖屬性 plt.figure(figsize=(12,6),dpi=80) plt.legend(loc='best') # plt.plot(fenzu,color='red') plt.bar(s,y,alpha=.5, color='r',width=0.8) plt.title('The one red and one blue ball number') plt.xlabel('one red and one blue number') plt.ylabel('times') #可以在圖中放置標(biāo)簽字符 # for i in range(0,19): # plt.text(int(i+1.4),25,x[i],color='b',size=10) # plt.text(1.4,20,x[0],color='g',ha='center') #將['1,12', '26,9', '5,13']這樣的字符放到圖中 plt.xticks(s,x, rotation=10,size=10,ha='left') plt.show()
結(jié)果如下:
可以看出紅球1和藍(lán)球12出現(xiàn)過的次數(shù)最多,其次是紅球26和藍(lán)球9
參考:
import matplotlib.pyplot as plt import numpy as np plt.rc('font', family='SimHei', size=13) num = np.array([13325, 9403, 9227, 8651]) ratio = np.array([0.75, 0.76, 0.72, 0.75]) men = num * ratio women = num * (1-ratio) x = ['聊天','支付','團(tuán)購(gòu)\n優(yōu)惠券','在線視頻'] width = 0.5 idx = np.arange(len(x)) plt.bar(idx, men, width, color='red', label='男性用戶') plt.bar(idx, women, width, bottom=men, color='yellow', label='女性用戶') plt.xlabel('應(yīng)用類別') plt.ylabel('男女分布') plt.xticks(idx+width/2, x, rotation=40) plt.legend()
關(guān)于“Python數(shù)據(jù)分析之如何實(shí)現(xiàn)雙色球統(tǒng)計(jì)單個(gè)紅和藍(lán)球哪個(gè)比例高”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。