หากต้องการคืนค่าไมโครวินาทีจากออบเจ็กต์ Timedelta ให้ใช้ timedelta.nanoseconds คุณสมบัติ. ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import pandas as pd
TimeDeltas เป็นไลบรารี datetime มาตรฐานของ Python ใช้การแทนค่า timedelta ที่แตกต่างกัน สร้างวัตถุ Timedelta
timedelta = pd.Timedelta('4 days 10 min 25 s 15 ms 33 ns')
แสดงไทม์เดลต้า
print("Timedelta...\n", timedelta) ส่งคืนค่านาโนวินาที
timedelta.nanoseconds
ตัวอย่าง
ต่อไปนี้เป็นรหัส
import pandas as pd
# TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s
# create a Timedelta object
timedelta = pd.Timedelta('4 days 10 min 25 s 15 ms 33 ns')
# display the Timedelta
print("Timedelta...\n", timedelta)
# return the nanoseconds value
res = timedelta.nanoseconds
# display the nanoseconds
print("\nTimedelta (nanoseconds value)...\n", res) ผลลัพธ์
ซึ่งจะได้รหัสดังต่อไปนี้
Timedelta... 4 days 00:10:25.015000033 Timedelta (nanoseconds value)... 33