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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • flowable 集成mongodb

    flowable 集成mongodb学无止境,活到老学到老,每天都问自己进步了吗?1.背景由于公司每天有至少1500个表单发起,处理待办任务至少7000个,累计历史任务数据已经达到200多w条,时间一长,通过数据库查询已办的任何和我发起的流程巨慢所以我们考虑到这些数据能不能放入ES或者是mongodb中流程中心1.0版本集成的是ES,速度确实非常快,提升查询性能近万倍,但是由于ES是一个全文检索的系统,对我们这些业务数据来说…

    2022年5月18日
    105
  • WebService接口

    WebService接口这是我在做对外部系统推送数据时自己写的WebService推送接口工具类,有几点需要注意1、我们调用对方的WebService接口,对方会给一个WebService接口的地址,供我们访问:http:

    2022年7月1日
    19
  • 1.1音响系统放大器设计

    1.1音响系统放大器设计​⑴了解集成功率放大器内部电路工作原理;​​⑵掌握其外围电路的设计与主要性能参数的测试方法;​​⑶掌握用运放与功率管设计音频功率放大电路的方法;​​(4)掌握运用电路仿真软件进行模拟电路辅助设计的方法;

    2022年5月8日
    46
  • 【我的Android进阶之旅】解决重写onTouch事件提示的警告:onTouch should call View#performClick when a click is detected

    【我的Android进阶之旅】解决重写onTouch事件提示的警告:onTouch should call View#performClick when a click is detected一、问题描述当你对一个控件(例如ImageView)使用setOnTouchListener()或者是对你的自定义控件重写onTouchEvent方法时会出现这个警告,警告内容全文如下:MyImageOnTouchListener#onTouchshouldcallView#performClickwhenaclickisdetectedless…(Ctrl+F…

    2022年6月17日
    32
  • oracle sql 字符串拼接_mysql将字符串和数字拼接

    oracle sql 字符串拼接_mysql将字符串和数字拼接一、MySQL在Java中我们通常用加号”+”来实现字符串的拼接,MySQL中也可以使用”+”来实现,比如:先加入测试数据CREATETABLEtest(idINT,nameVARCHAR(10),scoreFLOAT);INSERTINTOtestVALUES(1,’zhang’,98);INSERTINTOtestVALUES(2,’li’,95);Demo1SELECT…

    2025年11月30日
    10
  • html embed自动播放,html embed标签怎么用

    html embed自动播放,html embed标签怎么用HTMLembed 标签使用方法和属性详解一 基本语法代码如下 embedsrc url 说明 embed 可以用来插入各种多媒体 格式可以是 Midi Wav AIFF AU MP3 等等 Netscape 及新版的 IE 都支持 url 为音频或视频文件及其路径 可以是相对路径或绝对路径 示例 代码如下二 属性设置 1 自动播放 语法 autostart true false 说明 该属性规定音频或视频文件

    2025年12月10日
    5

发表回复

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

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