기간의 두 번째 구성요소를 가져오려면 period.second를 사용하세요. 특성. 먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
pandas.Period는 기간을 나타냅니다. 두 개의 기간 개체 만들기
period1 = pd.Period("2020-09-23 05:55:30")
period2 = pd.Period(freq="S", year = 2021, month = 7, day = 16, hour = 2, minute = 35, second = 10) 기간 개체 표시
print("Period1...\n", period1)
print("Period2...\n", period2) 두 개의 Period 개체에서 초 가져오기
res1 = period1.second res2 = period2.second
예시
다음은 코드입니다.
import pandas as pd
# The pandas.Period represents a period of time
# creating two Period objects
period1 = pd.Period("2020-09-23 05:55:30")
period2 = pd.Period(freq="S", year = 2021, month = 7, day = 16, hour = 2, minute = 35, second = 10)
# display the Period objects
print("Period1...\n", period1)
print("Period2...\n", period2)
# get the seconds from two Period objects
res1 = period1.second
res2 = period2.second
# Return the seconds from the two Period objects
print("\nSeconds component from the 1st Period object ...\n", res1)
print("\nSeconds component from the 1st Period object ...\n", res2) 출력
그러면 다음 코드가 생성됩니다.
Period1... 2020-09-23 05:55:30 Period2... 2021-07-16 02:35:10 Seconds component from the 1st Period object ... 30 Seconds component from the 1st Period object ... 10