Timestamp 객체에서 요일을 가져오려면 timestamp.weekday()를 사용하세요. 방법. 먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd import datetime
Pandas에서 타임스탬프를 설정합니다. 타임스탬프 개체 만들기
timestamp = pd.Timestamp(datetime.datetime(2021, 5, 12))
올해의 요일을 가져옵니다. 요일은 월요일 ==0, 화요일 ==1 … 일요일 ==6
으로 표시됩니다.timestamp.weekday()
예시
다음은 코드입니다.
import pandas as pd
import datetime
# set the timestamp in Pandas
# create a Timestamp object
timestamp = pd.Timestamp(datetime.datetime(2021, 5, 12))
# display the Timestamp
print("Timestamp...\n", timestamp)
# getting the weekday of the year
res = timestamp.weekday()
# display only the weekday
# weekday represented by number Monday == 0, Tuesday == 1 … Sunday == 6
print("\nGet the weekday from Timestamp...\n", res) 출력
그러면 다음 코드가 생성됩니다.
Timestamp... 2021-05-12 00:00:00 Get the weekday from Timestamp... 2