Python:彩票数据分析 !

作者: 14e61d025165 | 来源:发表于2019-05-12 16:54 被阅读2次

    昨天,我们用Python爬取了双色球彩票的开奖信息,并将开奖号码存储在Excel中。今天,我们对开奖号码进行分析,看看哪些号码开出来的多,哪些开出来的少?

    具体代码如下:

    Python学习交流群:1004391443,这里有资源共享,技术解答,还有小编从最基础的Python资料到项目实战的学习资料都有整理,希望能帮助你更了解python,学习python。

    <pre spellcheck="false" style="box-sizing: border-box; margin: 5px 0px; padding: 5px 10px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 16px; line-height: inherit; font-family: inherit; vertical-align: baseline; cursor: text; counter-reset: list-1 0 list-2 0 list-3 0 list-4 0 list-5 0 list-6 0 list-7 0 list-8 0 list-9 0; background-color: rgb(240, 240, 240); border-radius: 3px; white-space: pre-wrap; color: rgb(34, 34, 34); letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">#此程序用来分析双色球彩票的开奖数据信息
    from xlrd import open_workbook
    import matplotlib.pyplot as plt
    import numpy as np

    打开Excel文件

    rb = open_workbook('shuangseqiu.xls')
    sheet = rb.sheet_by_index(0)

    将数据区分来看,取出红球和篮球数

    reds=[]
    blues=[]
    for i in range(sheet.nrows - 1):
    reds.append(sheet.cell(i+1,2).value[:-2])
    blues.append(sheet.cell(i+1,2).value[-2:])

    画出红色球的柱形图

    plt.figure(figsize=(16, 12), dpi=100)

    plt.subplot(1, 2, 1)

    plt.figure(1)
    re1=[]

    统计处理红球信息

    for i in reds:
    for j in range(1,7):
    re1.append(i[(j-1)2:j2])

    print(re1)

    red01 = set(re1)
    dict01 = {}
    for item in red01:
    dict01.update({int(item): re1.count(item)})

    sorted(dict01.items(),key=lambda x:x[0])

    print('The redball totalnumber is:\n ',sorted(dict01.items(),key=lambda x:x[1],reverse=True))
    plt.bar(dict01.keys(),dict01.values(),0.5,color='r')
    plt.xticks(np.arange(0,34,1))
    for a,b in zip(dict01.keys(),dict01.values()):
    plt.text(a,b,b,ha='center',va='bottom',fontsize=10)

    plt.legend()

    plt.xlabel('The ball Number')
    plt.ylabel('Total Number')
    plt.title("The Red ball's statistics")
    plt.savefig('Redball.png')
    plt.show()

    画出蓝色球的柱形图

    plt.figure(2)

    统计处理篮球信息

    bu01 = set(blues)
    dict02 = {}
    for item in bu01:
    dict02.update({int(item): blues.count(item)})
    print('The blueball totalnumber is:\n ',sorted(dict02.items(),key=lambda x:x[1],reverse=True))
    plt.bar(dict02.keys(),dict02.values(),0.75)
    plt.xticks(np.arange(0,17,1))
    for a,b in zip(dict02.keys(),dict02.values()):
    plt.text(a,b,b,ha='center',va='bottom',fontsize=10)

    plt.legend()

    plt.xlabel('The ball Number')
    plt.ylabel('Total Number')
    plt.title("The Blue ball's statistics")
    plt.savefig('Blueball.png')
    plt.show()
    </pre>

    运行结果如下:

    1.直观的看一下:

    <tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1557651214022 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image <input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image> <tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1557651214024 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image

    <input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>

    2.统计分析:

    The redball totalnumber is:

    [(1, 474), (14, 472), (22, 469), (26, 468), (20, 465), (18, 460), (8, 457), (32, 457), (7, 454), (17, 451), (6, 451), (13, 445), (3, 443), (10, 442), (19, 441), (5, 440), (25, 439), (27, 439), (30, 438), (2, 436), (12, 432), (4, 431), (16, 431), (11, 430), (23, 429), (21, 428), (9, 425), (29, 419), (31, 414), (15, 413), (28, 410), (24, 395), (33, 374)]

    The blueball totalnumber is:

    [(12, 167), (9, 164), (16, 163), (11, 161), (14, 157), (7, 156), (1, 151), (13, 150), (5, 150), (15, 150), (6, 148), (3, 145), (10, 144), (2, 141), (4, 137), (8, 128)]

    红球:“1”出现的次数最多,“33”出现的次数最少

    篮球:“12”出现的次数最多,“8”出现的次数最少

    好了,See you!

    相关文章

      网友评论

        本文标题:Python:彩票数据分析 !

        本文链接:https://www.haomeiwen.com/subject/clgcaqtx.html