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

पायथन पैंडास - जांचें कि दिया गया CustomBusinessHour एंकर है या नहीं


दिए गए CustomBusinessHour की जांच करने के लिए कि यह एंकर है या नहीं, पैंडास में CustomBusinessHour.is_anchored() मेथड का उपयोग करें।

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

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) 

जांचें कि CustomBusinessHour एंकर है या नहीं:

print("\nCheck whether the CustomBusinessHour is anchored...\n", cbhOffset.is_anchored())

उदाहरण

निम्न कोड है:

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 whether the CustomBusinessHour is anchored print("\nCheck whether the CustomBusinessHour is anchored...\n", cbhOffset.is_anchored())

आउटपुट

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

Timestamp... 2021-11-14 05:20:30 CustomBusinessHour Offset...  Updated Timestamp... 2021-11-15 10:30:00 Check whether the CustomBusinessHour is anchored... True

  1. - पायथन में जांचें कि कोई स्ट्रिंग दिए गए नाम का टाइप किया गया संस्करण है या नहीं

    मान लीजिए हमारे पास दो लोअरकेस स्ट्रिंग्स s और t हैं। कभी-कभी जब हम एक स्वर (vowel) टाइप करते हैं, तो कुंजी देर तक दबी रह सकती है, और स्वर 1 या अधिक बार दोहराया जा सकता है। हमें यह जांचना है कि क्या संभव है कि t, s को इंगित करता हुआ टाइप किया गया संस्करण है। उदाहरण के लिए, यदि इनपुट s = mine, t = m

  1. पायथन प्रोग्राम: जांचें कि दी गई स्ट्रिंग पैंग्राम है या नहीं पायथन प्रोग्राम: जांचें कि दी गई स्ट्रिंग पैंग्राम है या नहीं

    इस लेख में, हम दिए गए प्रॉब्लम स्टेटमेंट को हल करने के समाधान और दृष्टिकोण के बारे में सीखेंगे। प्रॉब्लम स्टेटमेंट एक स्ट्रिंग इनपुट दिए जाने पर, हमें यह जांचने के लिए एक पायथन प्रोग्राम जनरेट करना होगा कि वह स्ट्रिंग पैंग्राम है या नहीं। एक पैंग्राम एक वाक्य/शब्दों की श्रृंखला है जिसमें अंग्रेजी

  1. - पायथन प्रोग्राम: जांचें कि दिया गया ऐरे मोनोटोनिक है या नहीं

    इस लेख में, हम दिए गए प्रॉब्लम स्टेटमेंट को हल करने के समाधान और दृष्टिकोण के बारे में सीखेंगे। प्रॉब्लम स्टेटमेंट एक ऐरे इनपुट Arr दिया गया है जिसमें n इंटीजर्स हैं। हमें जांचना होगा कि इनपुट ऐरे मोनोटोनिक प्रकृति का है या नहीं। एक ऐरे को मोनोटोनिक प्रकृति का कहा जाता है यदि यह लगातार बढ़ रहा है