重塑数据帧中的日期时间列值

2023-11-19

以下示例是关于Python中包含重塑数据帧中的日期时间列值用法的示例代码,想了解重塑数据帧中的日期时间列值的具体用法?重塑数据帧中的日期时间列值怎么用?重塑数据帧中的日期时间列值使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。

Ej. 日期为 10 分钟。

文件名:dt_reshape.py[英]:Reshape datetime column values in a dataframe源码类型:Python
import pandas as pd

def dt_reshape(df:pd.DataFrame, c_dt:str, dt_shape:str = "10MIN")->pd.DataFrame:
    # validate arguments
    assert c_dt in df.columns.tolist()
    # to x minutal
    df[c_dt] = df[c_dt].dt.floor(dt_shape).values
    # return
    return df

本文地址:https://www.itbaoku.cn/snippets/876619.html