ऑफ़सेट ऑब्जेक्ट पर लागू फ़्रीक्वेंसी का नाम वापस करने के लिए, पंडों में ऑफ़सेट.नाम प्रॉपर्टी का उपयोग करें। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
from pandas.tseries.frequencies import to_offset import pandas as pd
पंडों में टाइमस्टैम्प ऑब्जेक्ट सेट करें -
timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')
डेटऑफ़सेट बनाएं। हम यहां "M" फ़्रीक्वेंसी का उपयोग करके महीनों को बढ़ा रहे हैं -
offset = to_offset("3M") अपडेट किया गया टाइमस्टैम्प प्रदर्शित करें -
print("\nUpdated Timestamp...\n",timestamp + offset)
दिए गए DateOffset ऑब्जेक्ट पर लागू आवृत्ति का नाम लौटाएं -
print("\nThe name of the frequency on the DateOffset object..\n",
offset.name) उदाहरण
निम्नलिखित कोड है -
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 incrementing the months here using the "M" frequency
offset = to_offset("3M")
# Display the DateOffset
print("\nDateOffset...\n",offset)
# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + offset)
# return the name of the frequency applied on the given DateOffset object
print("\nThe name of the frequency on the DateOffset object..\n", offset.name) आउटपुट
यह निम्नलिखित कोड उत्पन्न करेगा -
Timestamp... 2021-09-26 03:25:02.000045 DateOffset... <3 * MonthEnds> Updated Timestamp... 2021-11-30 03:25:02.000045 The name of the frequency on the DateOffset object.. M