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.2.tar.gz (3.4 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.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for fastest_time_print_jhlong-1.0.2.tar.gz
Algorithm Hash digest
SHA256 9dc78911da002dd26edeceb39b98abd3b7fbc1f0e641564062bcb70e6496f973
MD5 328c8148b07c3c3502436d6311b04577
BLAKE2b-256 865363f4515b4c0547e48477ea67dd07475645a51d9dac2f33654c474ebd4b1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastest_time_print_jhlong-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c8b167f2795946c9cc3304398d18515e30536a123e5467a2098a4853f2c36cc
MD5 1f6707ae45b3c4f31972afc2ff2aec30
BLAKE2b-256 660e5818354c7c32068496cdf3ca17faedbdfe2cd4fa97bf152a84d3a017b41a

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