주어진 타임스탬프를 기간으로 변환하려면 timestamp.to_period()를 사용하세요. 방법. 그 안에서 freq를 사용하여 주파수를 설정합니다. 매개변수.
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
Pandas에서 타임스탬프 개체 설정
timestamp = pd.Timestamp('2021-09-14T15:12:34.261811624') 이제 타임스탬프를 기간으로 변환합니다. 값이 'M'인 "freq" 매개변수를 사용하여 빈도를 월로 설정했습니다.
timestamp.to_period(freq='M')
예시
다음은 코드입니다.
import pandas as pd
# set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-09-14T15:12:34.261811624')
# display the Timestamp
print("Timestamp...\n", timestamp)
# convert timestamp to Period
# we have set the frequency as Month using the "freq" parameter with value 'M'
print("\nTimestamp to Period...\n", timestamp.to_period(freq='M'))와 함께 "freq" 매개변수를 사용하여 빈도를 월로 설정했습니다. 출력
그러면 다음 코드가 생성됩니다.
Timestamp... 2021-09-14 15:12:34.261811624 Timestamp to Period... 2021-09