Python Pandas - 將給定 Period 物件的頻率從秒更改為分鐘頻率
要將給定 Period 物件的頻率從秒更改為分鐘頻率,請使用 **period.asfreq()** 方法並設定引數 **'T'**。
首先,匯入所需的庫 -
import pandas as pd
pandas.Period 表示一段時間。建立 Period 物件。我們使用 'freq' 引數將頻率設定為秒,即 'S'
period = pd.Period(freq="S", year = 2021, month = 9, day = 11, hour = 8, minute = 20, second = 45)
顯示具有秒頻率的 Period 物件
print("Period...\n", period)
將 Period 從秒轉換為分鐘頻率。我們使用 asfreq() 設定 "T" 將秒轉換為分鐘頻率
res = period.asfreq('T')示例
以下是程式碼
import pandas as pd
# The pandas.Period represents a period of time
# Creating a Period object
# We have set the frequency as seconds ie. 'S' using the 'freq' parameter
period = pd.Period(freq="S", year = 2021, month = 9, day = 11, hour = 8, minute = 20, second = 45)
# display the Period object with Seconds frequency
print("Period...\n", period)
# Convert Period from Seconds to Minutely frequency
# We have set the "T" to convert seconds to minutely frequency using asfreq()
res = period.asfreq('T')
# display the result after conversion from Seconds to Minutely frequency
print("\nFinal result after converting frequency ...\n", res)輸出
這將生成以下程式碼
Period... 2021-09-11 08:20:45 Final result after converting frequency ... 2021-09-11 08:20
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP