国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python數據分析之雙色球統計單個紅和藍球哪個比例高的方法

2020-02-22 23:06:17
字體:
來源:轉載
供稿:網友

本文實例講述了Python數據分析之雙色球統計單個紅和藍球哪個比例高的方法。分享給大家供大家參考,具體如下:

統計單個紅球和藍球,哪個組合最多,顯示前19組數據

#!/usr/bin/python# -*- coding:UTF-8 -*-import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport operatordf = pd.read_table('newdata.txt',header=None,sep=',')tdate = sorted(df.loc[:,0])# print tdateh1 = df.loc[:,1:7:6].values  #取第一列紅球和藍球# print h1h2 = df.loc[:,2:7:5].values  #取第二列紅球和藍球h3 = df.loc[:,3:7:4].valuesh4 = df.loc[:,4:7:3].valuesh5 = df.loc[:,5:7:2].valuesh6 = df.loc[:,6:7:1].values# tblue = df.loc[:,7]#將上方切分的所有數據組合到一起data = np.append(h1, h2, axis = 0)data = np.append(data, h3, axis = 0)data = np.append(data, h4, axis = 0)data = np.append(data, h5, axis = 0)data = np.append(data, h6, axis = 0)# print datadata1 = pd.DataFrame(data)# print data1#寫入到一個文件中data1.to_csv('hldata.csv',index=None,header=None)#讀取文件,將組合進行統計并從大到小排序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] = countsorted_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_dictfenzu = pd.DataFrame(sorted_count_dict).set_index([0])#print fenzu#分別從第一列和第二列取前19個數據放到x y中x = list(fenzu.index[:19])y = list(fenzu.values[:19])print xprint y#將x對應數值,不然畫圖報錯s = pd.Series(range(1,len(x)+1), index=x)#設置畫圖屬性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')#可以在圖中放置標簽字符# 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()

結果如下:

可以看出紅球1和藍球12出現過的次數最多,其次是紅球26和藍球9

參考:

import matplotlib.pyplot as pltimport numpy as npplt.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 * ratiowomen = num * (1-ratio)x = ['聊天','支付','團購/n優惠券','在線視頻']width = 0.5idx = np.arange(len(x))plt.bar(idx, men, width, color='red', label='男性用戶')plt.bar(idx, women, width, bottom=men, color='yellow', label='女性用戶')plt.xlabel('應用類別')plt.ylabel('男女分布')plt.xticks(idx+width/2, x, rotation=40)plt.legend()            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武平县| 大兴区| 南部县| 罗山县| 仪征市| 南平市| 苍溪县| 沙洋县| 贺州市| 彰化县| 三河市| 阳江市| 阿巴嘎旗| 五原县| 札达县| 蓬溪县| 黄浦区| 嘉禾县| 梅河口市| 河西区| 清水河县| 中方县| 高安市| 恩平市| 明水县| 栖霞市| 洱源县| 镇雄县| 清涧县| 西昌市| 东港市| 麟游县| 区。| 武宣县| 望江县| 类乌齐县| 武安市| 张家界市| 芦溪县| 大荔县| 陆良县|