Skip to main content

这个函数可以帮助你进行清洗数据,标准化、去重排序、最后切片打印的功能

Project description

fastest_time_print

项目简介

fastest_time_print 是一个结合 sanitize_jhlong 包的功能强大的数据处理函数。它用于从文件中读取时间数据, 进行标准化处理、去重、排序, 并输出最小的三个时间值

安装依赖

在使用此函数之前,请确保已安装 sanitize_jhlong 包:

pip install sanitize_jhlong

函数功能

  • 数据清洗:借助sanitize函数,将时间格式化为分钟.秒钟的标准形式。
  • 去重处理:自动去除重复时间记录。
  • 排序输出:将时间从小到大排序,返回前三个最快的时间值。

函数定义

from sanitize_jhlong import sanitize

def fastest_time_print(data_file):
    '''
    从文件中读取时间数据,标准化、去重、排序,并返回前三个时间值。
    
    参数:
    - data_file: 字符串类型,包含时间数据的文件路径。

    返回值:
    - 一个列表,包含按升序排列的前三个时间值(字符串格式)。
    - 如果文件无法读取,返回 None 并打印错误信息。
    '''
    try:
        with open(data_file) as f:
            data = f.readline()
        data_clean = data.strip().split(',')
        good_data = sorted(set(sanitize(each_t) for each_t in data_clean))[0:3]
        return good_data      
    except IOError as err:
        print('find file error' + str(err))
        return None

使用方法

假设有一个名为james.txt的文件,内容如下:

 2:45,1-23,1:02,2:34,2:45,1-23

调用实例:

from sanitize_jhlong import sanitize
from my_time_library import fastest_time_print

# 调用函数处理时间数据
result = fastest_time_print("james.txt")
print(result)  # 输出 ['1.02', '1.23', '2.34']

参数说明

data_file:包含逗号分隔时间数据的文件路径,字符串类型

返回值

  • 一个包含排序后前三个时间值的列表。
  • 如果文件读取失败,返回 None,并打印错误信息。

实例输出

对于以下文件内容:

3:21,2:45,1-15,2:34,1:15,2:45

运行代码:

result = fastest_time_print("james.txt")
print(result)

输出结果为:

['1.15', '2.34', '2.45']

贡献指南

如果您有兴趣为 sanitize-jhlong项目做出贡献,欢迎提交 pull request 或 issue! 我们乐意接受任何有助于改进项目的反馈和建议。

联系方式

如果您在使用过程中遇到问题,请联系作者:jhlong2024@163.com

makdown使用方法

  • 标题(#):用 # 表示一级标题,## 表示二级标题。
  • 代码块(```):使用三个反引号来包裹代码,使代码以块的形式显示。可以在反引号后面写上代码语言(如 python),这样会有语法高亮。
  • 列表(-):用 -* 表示无序列表。(确保每个 - 号后面有空格)
  • 如果您想使用斜体,可以将内容包裹在单个*中;使用粗体则用两个 * 这是斜体文本 这是粗体文本

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastest_time_print_jhlong-1.0.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastest_time_print_jhlong-1.0.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file fastest_time_print_jhlong-1.0.1.tar.gz.

File metadata

File hashes

Hashes for fastest_time_print_jhlong-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ab9cbc94568b4ef81f10ecebf334935357c8dc10160d764f9bb0ebb503731f14
MD5 4e4c7057deee597e7fc77ac8ea45abe8
BLAKE2b-256 5c81cebdb7552101a1a9520b13b4f37a6226b5ad0bfee8c4cab5d8a607df5368

See more details on using hashes here.

File details

Details for the file fastest_time_print_jhlong-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastest_time_print_jhlong-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0bc22cae35159b3153a832f53e110c33dfa065062e469977456b99e44fcf4347
MD5 c112cdff8561b49613fc196a16db3490
BLAKE2b-256 5372827ea69d9baca3b8b719ba67615c7c2aef3cbe58e177ef9ca111040a3c90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page