Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

पायथन पैंडास CustomBusinessHour - जांचें कि दिया गया टाइमस्टैम्प ऑफसेट पर है या नहीं


दिए गए टाइमस्टैम्प की जांच करने के लिए कि यह ऑफसेट पर है या नहीं, पैंडास में CustomBusinessHour.is_on_offset() का उपयोग करें। जांच के लिए टाइमस्टैम्प को तर्क के रूप में पास करें।

सबसे पहले, आवश्यक लाइब्रेरी आयात करें:

import pandas as pd

पैंडास में टाइमस्टैम्प ऑब्जेक्ट सेट करें:

timestamp = pd.Timestamp('2021-11-14 05:20:30') 

CustomBusinessHour ऑफसेट बनाएं। CustomBusinessHour DateOffset सबक्लास है:

cbhOffset = pd.tseries.offsets.CustomBusinessHour(start="09:30", end = "18:30")

ऑफसेट को टाइमस्टैम्प में जोड़ें और अपडेटेड टाइमस्टैम्प प्रदर्शित करें:

print("\nUpdated Timestamp...\n",timestamp + cbhOffset) 

जांचें कि दिया गया टाइमस्टैम्प ऑफसेट पर है या नहीं:

offset = cbhOffset.is_on_offset(pd.Timestamp('2021-11-20 05:20:30'))

परिणाम प्रदर्शित करें:

print("\nCheck if the given timestamp is on offset or not...\n",offset) 

उदाहरण

निम्न कोड है:

import pandas as pd # Set the timestamp object in Pandas timestamp = pd.Timestamp('2021-11-14 05:20:30') # Display the Timestamp print("Timestamp...\n",timestamp) # Create the CustomBusinessHour Offset # CustomBusinessHour is the DateOffset subclass # Here, "start" is the start time of your custom business hour in 24h format. # The "end" is the end time of your custom business hour in 24h format. cbhOffset = pd.tseries.offsets.CustomBusinessHour(start="09:30", end = "18:30") # Display the CustomBusinessHour Offset print("\nCustomBusinessHour Offset...\n",cbhOffset) # Add the offset to the Timestamp and display the Updated Timestamp print("\nUpdated Timestamp...\n",timestamp + cbhOffset) # Check if the given timestamp is on offset or not offset = cbhOffset.is_on_offset(pd.Timestamp('2021-11-20 05:20:30')) # display the result print("\nCheck if the given timestamp is on offset or not...\n",offset)

आउटपुट

यह निम्न कोड उत्पन्न करेगा:

Timestamp... 2021-11-14 05:20:30 CustomBusinessHour Offset...  Updated Timestamp... 2021-11-15 10:30:00 Check if the given timestamp is on offset or not... False

  1. - पायथन पैंडास - UTC ऑफसेट टाइम प्राप्त करें

    UTC ऑफसेट टाइम प्राप्त करने के लिए timestamp.utcoffset() का उपयोग करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें: import pandas as pd टाइमस्टैम्प बनाएं: timestamp = pd.Timestamp(2021-10-16T15:12:34.261811624, tz=UTC) UTC दिन और समय के साथ नया टाइमस्टैम्प: timestamp.utcnow() UTC ऑफसेट टाइम प्राप्त कर

  1. - Python में दी गई संख्या यूक्लिड नंबर है या नहीं जांचें

    मान लीजिए हमारे पास एक संख्या n है। हमें जांचना है कि n यूक्लिड नंबर है या नहीं। जैसा कि हम जानते हैं यूक्लिड संख्याएं पूर्णांक हैं जिन्हें इस रूप में दर्शाया जा सकता है:n= Pn+1जहां पहले n अभाज्य संख्याओं का गुणनफल है।तो, यदि इनपुट n = 211 जैसा है, तो आउटपुट True होगा n को इस रूप में दर्शाया जा सकता

  1. - पायथन में जांचें कि दी गई संख्या ओर संख्या (Ore Number) है या नहीं

    मान लीजिए हमारे पास एक संख्या n है। हमें जांचना है कि n एक ओर संख्या (Ore number) है या नहीं। जैसा कि हम जानते हैं, एक ओर संख्या वह संख्या होती है जिसके भाजकों का हार्मोनिक माध्य एक पूर्णांक होता है। उदाहरण के लिए, यदि इनपुट 28 है, तो आउटपुट True होगा क्योंकि 28 के छह भाजक हैं: [1, 2, 4, 7, 14, 28]