Python Pandas - 获取 Period 的小时部分中的分钟
pythonpandasserver side programmingprogramming更新于 2026/1/2 18:20:17
要获取 Period 的小时部分中的分钟,请使用 period.minute 属性。首先,导入所需的库 −
import pandas as pd
pandas.Period 表示一段时间。创建两个 Period 对象
period1 = pd.Period("2020-09-23 05:55:30")
period2 = pd.Period(freq="T", year = 2021, month = 7, day = 16, hour = 2,minute = 35)
显示 Period 对象
print("Period1...\n", period1)
print("Period2...\n", period2)
从两个 Period 对象获取小时中的分钟
res1 = period1.minute res2 = period2.minute
示例
以下是代码
import pandas as pd
# pandas.Period 表示一段时间
# 创建两个 Period 对象
period1 = pd.Period("2020-09-23 05:55:30")
period2 = pd.Period(freq="T", year = 2021, month = 7, day = 16, hour = 2,minute = 35)
# 显示 Period 对象
print("Period1...\n", period1)
print("Period2...\n", period2)
#从两个 Period 对象中获取小时中的分钟
res1 = period1.minute
res2 = period2.minute
# 从两个 Period 对象中返回小时中的分钟
print("\n第一个 Period 对象中的小时中的分钟...\n", res1)
print("\n第二个 Period 对象中的小时中的分钟...\n", res2)
输出
将生成以下代码
Period1... 2020-09-23 05:55:30 Period2... 2021-07-16 02:35 第一个 Period 对象中的小时中的分钟... 55 第二个 Period 对象中的小时中的分钟... 35
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

