This article example describes the Python data analysis of the two-color ball statistics of two red and blue ball which combination of high proportion of the method. Shared for your reference, as follows:
Counting two red and blue balls, which combination is the most, showing the first 19 sets of data
#!/usr/bin/python # -*- coding:UTF-8 -*- import pandas as pd import numpy as np import as plt import operator #Import data df = pd.read_table('',header=None,sep=',') tdate = sorted([:,0]) # print tdate # Red balls in columns 1 and 2 h1 = [:,1:2].values # print h1 # Red balls in columns 2 and 3 h2 = [:,2:3].values # Red balls in columns 3 and 4 h3 = [:,3:4].values # Red balls in columns 4 and 5 h4 = [:,4:5].values # Red balls in columns 5 and 6 h5 = [:,5:6].values #Blueball. b1 = [:,7:7].values # print b1 #1 and 3 red balls h6 = [:,1:3:2].values h7 = [:,1:4:3].values h8 = [:,1:5:4].values h9 = [:,1:6:5].values h10 = [:,2:4:2].values h11 = [:,2:5:3].values h12 = [:,2:6:4].values h13 = [:,3:5:2].values h14 = [:,3:6:3].values # Red balls in columns 4 and 6 h15 = [:,4:6:2].values # Add blue balls to each red ball group (2 columns of data become 3 columns of data), then merge all the data by columns. data2 = (h1, b1, axis=1) for i in [h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14,h15]: data1 = (i, b1, axis=1) data2 = (data2, data1, axis=0) print data2 data1 = (data2) # Write to file data1.to_csv('',index=None,header=None) # Read the files, count them, and sort them in descending order. f = open("") count_dict = {} for line in (): line = () count = count_dict.setdefault(line, 0) count += 1 count_dict[line] = count sorted_count_dict = sorted(count_dict.iteritems(), key=(1), reverse=True) # for item in sorted_count_dict: # print "%s,%d" % (item[0], item[1]) #Reset the index of the DataFrame fenzu = (sorted_count_dict).set_index([0]) print fenzu x = list([:19]) y = list([:19]) print x print y # Replace index with a numeric value for ease of use in graphing. s = (range(1,len(x)+1), index=x) (figsize=(12,8),dpi=80) (loc='best') (s,y,alpha=.5, color='r',width=0.8) ('The two red and one blue ball number') ('two red and one blue number') ('times') # Show the content of the original index (s,x, rotation=30,size=10,ha='left') ()
Show results:
It can be seen that red balls 20, 26 and blue ball 9, as well as red balls 17, 21 and blue ball 14, appear up to 12 times
The later stats for 3 red and blue, 4 red and blue, 5 red and blue, and 6 red and blue are basically along the same lines.
Readers interested in more Python related content can check out this site's topic: theSummary of Python mathematical operations techniques》、《Summary of Python string manipulation techniques》、《Summary of Python coding manipulation techniques》、《Python Data Structures and Algorithms Tutorial》、《Summary of Python function usage tips》、《Python introductory and advanced classic tutorialsand theSummary of Python file and directory manipulation techniques》
I hope that what I have said in this article will help you in Python programming.