Python Pandas - 将 Period 对象作为具有每月频率的时间戳返回
要将Period对象作为具有每月频率的时间戳返回,请使用该方法并将freq参数设置为“M”。period.to_timestamp()
首先,导入所需的库-
import pandas as pd
的pandas.Period代表的一段时间。创建Period对象
period = pd.Period(freq="S", year = 2021, month = 9, day = 18, hour = 17, minute = 20, second = 45)
显示Period对象
print("Period...\n", period)返回Period对象的时间戳表示。我们已经使用“freq”参数设置了频率。频率设置为“M”,即每月
print("\nPeriod to Timestamp with monthly (month-end) frequency...\n",
period.to_timestamp(freq='M'))示例
以下是代码
import pandas as pd
#Thepandas.Periodrepresentsaperiodoftime
#CreatingaPeriodobject
period = pd.Period(freq="S", year = 2021, month = 9, day = 18, hour = 17, minute = 20, second = 45)
#displaythePeriodobject
print("Period...\n", period)
#ReturntheTimestamprepresentationofthePeriodobject
# We have set the frequency using the "freq" parameter
# The frequency is set as 'M' i.e. monthly
print("\nPeriod to Timestamp with monthly (month-end) frequency...\n", period.to_timestamp(freq='M'))输出结果这将产生以下代码
Period... 2021-09-18 17:20:45 Period to Timestamp with monthly (month-end) frequency... 2021-09-30 00:00:00
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短