주어진 기간 객체의 빈도를 초에서 매일 빈도로 변경하려면 period.asfreq()를 사용하세요. 메소드를 입력하고 매개변수 'D'를 설정합니다.
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
pandas.Period는 기간을 나타냅니다. 기간 개체 만들기. 주파수를 초로 설정했습니다. 'freq' 매개변수를 사용하는 'S'
period = pd.Period(freq="S", year = 2021, month = 4, day = 16, hour = 2, minute = 35, second = 15)
초 빈도로 기간 개체 표시
print("Period...\n", period)
기간을 초에서 일일 빈도로 변환합니다. asfreq()를 사용하여 초를 일일 빈도로 변환하도록 "D"를 설정했습니다.
res = period.asfreq('D') 예시
다음은 코드입니다.
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 = 4, day = 16, hour = 2, minute = 35, second = 15)
# display the Period object with Seconds frequency
print("Period...\n", period)
# Convert Period from Seconds to Daily frequency
# We have set the "D" to convert seconds to daily frequency using asfreq()
res = period.asfreq('D')
# display the result after conversion from Seconds to Daily frequency
print("\nFinal result after converting frequency ...\n", res) 출력
그러면 다음 코드가 생성됩니다.
Period... 2021-04-16 02:35:15 Final result after converting frequency ... 2021-04-16