Python数据分析的过程记录(二)

Python数据分析的过程记录(二)Python数据分析的过程记录(二)文章目录Python数据分析的过程记录(二)一、需求介绍二、需求分析三、代码实现一、需求介绍二、需求分析三、代码实现

大家好,又见面了,我是你们的朋友全栈君。

Python数据分析的过程记录(二)

一、需求介绍

在本篇博文中,我们在使用另外一种方法来进行彩票的数据分析,这种方法我们称之为滚雪球,即就是说需要不断地迭代来进行彩票的购买与预计估算等操作。

我们要买的彩票名称叫“极速赛车”

链接例如:

https://www.1681160.com/api/pks/getPksHistoryList.do’?date=2021-07-05&lotCode=10037

这个是数据存储的网页的链接,如果想更严谨一点的话,他是Ajax的模式。

二、需求分析

1、简介

根据上面的需求介绍,我们大致明白了要干什么。

2、获取数据

不管进行怎样的分析,我们都需要进行数据的获取或者说是提取,在这里呢,我们就采用爬虫的方式来进行数据的获取。

我们使用了Python中的requests模块来进行爬虫的操作,从而获取到了,不同天的彩票的基本数据:

2.1、时间信息

2.2、开奖的数字信息

2.3、其他需要的信息等

3、数据分析的方案

我们首先定义一个列表,这个列表之中会记录一些数据,我们根据这个列表中的数据来进行下一次的彩票的购买,具体的方案如下:
1、我们购买的数据应该要满足,他们全都在这个列表之中,即就是说,列表之中的数据我们都要购买,不管中不中我们都买:
2、如果中了,那么我们就把这个数据从当前的列表里面剔除出去,如果没有中,那么我们就把这个数据加入到列表里面去,;
3、如上所述,我们依次的向下进行推进着进行购买彩票。

这就是我们的一个新的方案。

下面就是具体的代码实现了。

三、代码实现

在代码里面有一些注释,根据这些注释以及相关代码是可以理解具体的意图的啦。

import re
import requests
import xlwt
import json

""" 数字 位置 天数 数据 """

# 时间列表
date_list = ["7-01", "7-02", "7-03"]
for i in range(30):
    date_list.append(f"6-{ 
     i + 1}")


for number in ["01", "02", "03", "04", "05", 
               "06", "07", "08", "09", "10"]:

    wb = xlwt.Workbook()  # 创建 excel 表格
    # 每一个数字对应于一个 excel 表格

    for position_of_the_lottery in range(10):

        sh = wb.add_sheet(f'彩票分析数据处理{ 
     position_of_the_lottery}')
        # 创建一个 表单
        """ 表头 """
        sh.write(0, 0, "日期")
        sh.write(0, 1, "48次中的数目")
        sh.write(0, 2, "48次中的时间")
        sh.write(0, 3, "49次中的数目")
        sh.write(0, 4, "49次中的时间")
        sh.write(0, 5, "50次中的数目")
        sh.write(0, 6, "50次中的时间")
        sh.write(0, 7, "51次中的数目")
        sh.write(0, 8, "51次中的时间")
        sh.write(0, 9, "52次中的数目")
        sh.write(0, 10, "52次中的时间")
        sh.write(0, 11, "53次中的数目")
        sh.write(0, 12, "53次中的时间")
        sh.write(0, 13, "54次中的数目")
        sh.write(0, 14, "54次中的时间")
        sh.write(0, 15, "55次中的数目")
        sh.write(0, 16, "55次中的时间")
        sh.write(0, 17, "56次中的数目")
        sh.write(0, 18, "56次中的时间")
        sh.write(0, 19, "57次中的数目")
        sh.write(0, 20, "57次中的时间")
        sh.write(0, 21, "58次中的数目")
        sh.write(0, 22, "58次中的时间")
        sh.write(0, 23, "59次中的数目")
        sh.write(0, 24, "59次中的时间")
        sh.write(0, 25, "60次中的数目")
        sh.write(0, 26, "60次中的时间")
        sh.write(0, 27, "61次中的数目")
        sh.write(0, 28, "61次中的时间")
        sh.write(0, 29, "62次中的数目")
        sh.write(0, 30, "62次中的时间")
        sh.write(0, 31, "63次中的数目")
        sh.write(0, 32, "63次中的时间")
        sh.write(0, 33, "64次中的数目")
        sh.write(0, 34, "64次中的时间")
        # 绘制表头

        excel_position_of_the_mouse = 1
        # 这个应该是一个表一个
        # 所以说哦 需要放在外面


        for date in date_list:

            url = 'https://www.1681160.com/api/pks/getPksHistoryList.do' \
                  f'?date=2021-0{ 
     date}&lotCode=10037'
            headers = { 
   
                'User-Agent':
                    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
                    '(KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.64',
                'X-Requested-With':
                    'XMLHttpRequest'
            }  # Ajax 请求
            response_0 = requests.get(url=url, headers=headers)
            new_response_0 = json.loads(response_0.content.decode())["result"]["data"]
            # 获取数据

            # 初始化
            # global
            times_of_the_number_of_coming = 1  # 初始化数目

            # 每一天都需要进行初始化 date

            dict_of_times = { 
   }  # 次数统计 dict
            dict_of_t = { 
   }  # 时间统计 dict

            # excel_position_of_the_mouse = 1

            for the_data_of_the_daily_lottery in range(1152):

                # 1152 条数据

                a_result = new_response_0[1151 - the_data_of_the_daily_lottery][
                               "preDrawCode"][0 + 3 * position_of_the_lottery:
                                              2 + 3 * position_of_the_lottery]

                if a_result == number:  # 如果得到的结果 == 开始的数字
                    # 如果相等,那就是命中了

                    if f'{ 
     times_of_the_number_of_coming}' in dict_of_times.keys():
                        dict_of_times[f'{ 
     times_of_the_number_of_coming}'] += 1
                    else:
                        dict_of_times[f'{ 
     times_of_the_number_of_coming}'] = 1

                    if f'{ 
     times_of_the_number_of_coming}' in dict_of_t.keys():
                        dict_of_t[f'{ 
     times_of_the_number_of_coming}'].append(
                            new_response_0[1151 - the_data_of_the_daily_lottery][
                                "preDrawTime"][10:]
                        )
                    else:
                        dict_of_t[f'{ 
     times_of_the_number_of_coming}'] = [
                            new_response_0[1151 - the_data_of_the_daily_lottery][
                                "preDrawTime"][10:]
                        ]

                    print(times_of_the_number_of_coming)
                    times_of_the_number_of_coming = 1

                    # 重置
                else:
                    # 如果不相等那就是没有命中
                    # 那么,我们需要自加一
                    
                    times_of_the_number_of_coming += 1  # 自加一

            # 书写时间

            sh.write(excel_position_of_the_mouse, 0,
                     new_response_0[0]["preDrawTime"][:10])
            # 时间写在第一列上面,时间随便取一个就可以了


            for e in dict_of_times.keys():
                if int(e) >= 48:
                    sh.write(excel_position_of_the_mouse,
                             1 + (int(e) - 48) * 2,
                             dict_of_times[e])
                    sh.write(excel_position_of_the_mouse,
                             2 + (int(e) - 48) * 2,
                             dict_of_t[e])
                    # 写入次数以及时间
                else:
                    continue
                    # 小于 48 的不记入数据里面

            excel_position_of_the_mouse += 1
            # 当搞完一个以后,需要改变一下位置


    # 保存
    wb.save(f'极速赛车滚雪球数据统计-{ 
     number}.xls')

四、成品结果展示

最后我们的成果是一个文件夹,
里面有十个excel表格,因为有十个数字需要进行滚雪球方式的寻找与查看。

同时,每一个excel表格中有十个表单,因为每一个数字都需要有十个位置需要统计。

成果的截图如下所示;

图1
在这里插入图片描述

图2
在这里插入图片描述

图3

在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/160366.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • openssl 创建 pfx 证书

    openssl 创建 pfx 证书环境:centos7.6,openssl1.02k-fips生成私钥[root@ansible002keyfile]#opensslgenrsa-outserver.key1024GeneratingRSAprivatekey,1024bitlongmodulus……++++++…++++++eis65537(0x10001)生成证书请求文件,需要填写信息,例如:cn/gd/zh/sourcecode/bdc/www.a.com[root@

    2022年5月2日
  • c# 操作ad域用户

    c# 操作ad域用户测试环境:win2008r2服务器ad域服务器安装参考:https://www.cnblogs.com/cnjavahome/p/9029665.html密码策略修改参考:https://blog.csdn.net/zouyujie1127/article/details/40857675工作机dns设置为ad域服务器的ipusing:usingSystem.DirectoryServ…

    2022年5月16日
  • ReportingServies——SQLServer报表开发综合实例

    ReportingServies——SQLServer报表开发综合实例上一篇:ReportingServies报表开发实例教程如果我们安装了sqlserver2008 R2,将会自动安装一个报表开发工具不要以为此报表开发工具只适合于sqlserver2008,其实在sqlserver2012中也是支持的,事实上我现在项目中就是使用的sqlserver2012。使用此工具进行报表开发,将会十分快速而且方便。这里我通过一个综合实例来演示它的使用技

    2022年10月21日
  • pycharm设置项目路径_vscode和pycharm区别

    pycharm设置项目路径_vscode和pycharm区别#-*-coding=utf-8-*-#@Time:${DATE}${TIME}#@Author:Donvink${USER}#@Site:${SITE}#@File:${NAME}.py#@Software:${PRODUCT_NAME}

    2022年8月25日
  • 任意角和弧度制[通俗易懂]

    任意角和弧度制[通俗易懂]1importmath23PI=math.pi45defshow():6print(7'小主,(* ̄︶ ̄),请选择你需要的功能:\n'8'\t\0

    2022年8月4日
  • hisi3516dv300学习笔记——编译hisi3516dv300的SDK

    hisi3516dv300学习笔记——编译hisi3516dv300的SDK先下载linux内核源码包,下载地址:https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/(1)编译整个osdrv目录:注意:默认不发布内核源码包,只发布补丁文件。内核源码包需自行从开源社区上下载。从linux开源社区下载v4.9.37版本的内核:1)进入网站:www.kernel.org2)选择HTTP协议资源的https://www.kernel.org/pub/选项,进入子页面3)选择linux/菜单项,进入子页面4)选择ker

    2022年9月23日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号