หากต้องการรับวันทำงานจากออบเจ็กต์ 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