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.0.tar.gz (2.7 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.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for fastest_time_print_jhlong-1.0.0.tar.gz
Algorithm Hash digest
SHA256 673d2adc0d330a023c88c7d197d13f81c05c8d492063e7e0a7db68bd38a8f876
MD5 1698c37e8b63049281ae1c7b1c80102e
BLAKE2b-256 c98856eb993e6f4865ec9556f6883c51dc4ac1cf4c4c9fadd1ac0b55d35c8577

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastest_time_print_jhlong-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 475655fe4e741f85ef6e9d77876aeea55b9682e3daae9149f4a43026bb9d6da8
MD5 9e8e5a4a4fc660b8a353f0718b6c0e8b
BLAKE2b-256 e9ba6bc5f2cdb5d4bf90e456c15ec1156bd986272942166ce30938eebb76bbc8

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