python資料分析2 雙色球 藍紅球分析統計

2021-07-11 20:31:33 字數 2933 閱讀 1169

newdata.txt資料樣子

...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

...一、藍球統計:

analyze_data_lan.py

#!/usr/bin/python

# -*- coding:utf-8 -*-

#呼叫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開始為第一行,1代表第二行,不包含第四行)

# print df.loc[0:10,:] #第1行到第9行的全部列

# print df.loc[:,[0,7]] #全部行的第1和第8列

tdate = sorted(df.loc[:,0]) #取第一列資料

# print tdate

tdate1 = #將tdate資料讀取到列表中

for i in tdate:

print tdate1

# s = pd.series(tdate1, index=tdate1)

s = pd.series(range(1,len(tdate1)+1), index=tdate1) #將日期轉換為對應的數值從1開始

# print s

tblue = list(reversed(df.loc[:,7])) #對資料取反

print tblue

fenzu = pd.value_counts(tblue,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='b',width=0.8) #直方圖引數設定

plt.title('the blue ball number') #標題

plt.xlabel('blue number') #x軸內容

plt.ylabel('times') #y軸內容

plt.show() #顯示圖

結果輸出:

看來藍球9選中最多

二、紅球統計

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]

#將資料合併到一起

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()

結果輸出:

紅球1、7、14、17、26選中機率高些

python爬取雙色球歷史資料 爬取雙色球歷史資料

爬取雙色球歷史資料 需要的包 beautifulsoup install 指令碼如下 執行後生成的資料json處理後存在data檔案中 coding utf 8 import urllib import re import json from bs4 import beautifulsoup li ...

資料分析2

在原始arxiv資料集中 作者authors欄位是乙個字串格式,其中每個作者使用逗號進行分隔分,所以我們我們首先需要完成以下步驟 在python中字串是最常用的資料型別,可以使用引號 或 來建立字串。python中所有的字元都使用字串儲存,可以使用方括號來擷取字串。如下例項 an highlight...

python資料分析

以網路爬蟲為例,網路爬蟲是乙個自動提取網頁的程式,爬蟲是搜尋引擎的第一步,也是最容易的一部。網頁搜尋,建立索引,查詢排序 用c c 效率高,速度塊,適合通用搜尋引擎做往往爬取。但是它的缺點也特別明顯 開發慢,寫起來又臭又長的。而python無論在資料分析還是在指令碼自動化編寫尚都是簡單,易學的。良好...