यह जाँचने के लिए कि दी गई डेटऑफ़सेट एंकर है या नहीं, पंडों में ऑफ़सेट.is_anchored () विधि का उपयोग करें। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
from pandas.tseries.frequencies import to_offset import pandas as pd
पंडों में टाइमस्टैम्प ऑब्जेक्ट सेट करें -
timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')
डेटऑफ़सेट बनाएं। हम यहां मंगलवार के लिए एंकर ऑफ़सेट यानी साप्ताहिक आवृत्ति का उपयोग कर रहे हैं -
offset = to_offset("W-TUE") अपडेट किया गया टाइमस्टैम्प प्रदर्शित करें -
print("\nUpdated Timestamp...\n",timestamp + offset)
जांचें कि क्या डेटऑफ़सेट एंकर है -
print("\nCheck whether the DateOffset is anchored...\n", offset.is_anchored()) उदाहरण
निम्नलिखित कोड है -
from pandas.tseries.frequencies import to_offset
import pandas as pd
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')
# Display the Timestamp
print("Timestamp...\n",timestamp)
# Create the DateOffset
# We are using the Anchored offset i.e. weekly frequency here for Tuesday
offset = to_offset("W-TUE")
# Display the DateOffset
print("\nDateOffset...\n",offset)
# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + offset)
# Check whether the DateOffset is anchored
print("\nCheck whether the DateOffset is anchored...\n", offset.is_anchored()) आउटपुट
यह निम्नलिखित कोड उत्पन्न करेगा -
Timestamp... 2021-09-26 03:25:02.000045 DateOffset... <Week: weekday=1> Updated Timestamp... 2021-09-28 03:25:02.000045 Check whether the DateOffset is anchored... True