# Python data analysis-blue-red ball in two-color ball analysis statistical example, python Data Analysis

Source: Internet
Author: User

Python data analysis-blue-red ball in two-color ball analysis statistical example, python Data Analysis

This article describes the two-color ball blue-red ball analysis statistics of Python data analysis. We will share this with you for your reference. The details are as follows:

Next, let's take a look at the previous Python data analysis to get the data processing for the collection of two-color ball history information,

Newdata.txt Data Format

...
, 15
, 04
, 05
...

I. Blue ball statistics:

Analyze_data_lan.py

`#! /Usr/bin/python #-*-coding: UTF-8-*-# Call pandas numpy matplotlib package import pandas as pdimport numpy as npimport matplotlib. pyplot as plt(read newdata.txt file df = pd.read_table('newdata.txt ', header = None, sep = ',') # print df [] # 2nd to 3rd rows (index 0 starts with the first row, 1 indicates the second row, excluding the fourth row) # print df. loc [,:] # All columns from 1st rows to 9th rows # print df. loc [:, [1st] # tdate = sorted (df. loc [:, 0]) # retrieve the first column of data # print tdatetdate1 = [] # Read tdate data to the list 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) # convert a date to a corresponding value starting from 1 # print stblue = list (reversed (df. loc [:, 7]) # reverse print tbluefenzu = pd for the data. value_counts (tblue, ascending = False) # group the data for statistics and sort print fenzux = list (fenzu. index [:]) # obtain the blue number y = list (fenzu. values [:]) # obtain the blue statistical quantity print xprint y # print type (fenzu) plt. figure (figsize = (10, 6), dpi = 70) # configure the drawing size and fineness plt. legend (loc = 'best') # plt. plot (fenzu, color = 'red') # plot plt. bar (x, y, alpha =. 5, color = 'B', width = 0.8) # Set plt in the histogram parameter. title ('The blue ball number') # title plt. xlabel ('Blue number') # X axis content plt. ylabel ('times ') # The content of the Y axis plt. show () # display chart`

Result output:

It seems that the blue ball 9 is selected at most

Ii. Red Ball statistics

Analyze_data_hong.py

`#! /Usr/bin/python #-*-coding: UTF-8-*-import pandas as pdimport numpy as npimport matplotlib. pyplot as plt # Read the file df = pd.read_table('newdata.txt ', header = None, sep =', ') # print df [] # print df. loc [0: 10,:] # print df. loc [:, 1:6] tdate = sorted (df. loc [:, 0]) # print tdateh1 = df. loc [:, 1] h2 = df. loc [:, 2] h3 = df. loc [:, 3] h4 = df. loc [:, 4] h5 = df. loc [:, 5] h6 = df. loc [:, 6] # Merge data together 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 fenzux = list (fenzu. index [:]) y = list (fenzu. values [:]) print xprint 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 ()`

Result output:

Red Balls 1, 7, 14, 17, and 26 are more likely to be selected.

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.