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

पायथन पांडा - BusinessHour ऑफ़सेट ऑब्जेक्ट से 24 घंटों के प्रारूप में कस्टम व्यावसायिक घंटे का समाप्ति समय प्रदर्शित करें

BusinessHour ऑफ़सेट ऑब्जेक्ट से कस्टम व्यावसायिक घंटे के समाप्ति समय को 24h स्वरूप में प्रदर्शित करने के लिए, BusinessHour.end गुण का उपयोग करें।

सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -

import pandas as pd

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

timestamp = pd.Timestamp('2021-9-30 06:50:20')

BusinessHour ऑफ़सेट बनाएँ। यहां, "प्रारंभ" 24 घंटों के प्रारूप में आपके कस्टम व्यावसायिक घंटे का प्रारंभ समय है। "समाप्ति" 24 घंटों के प्रारूप में आपके कस्टम व्यावसायिक घंटे का समाप्ति समय है -

bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00", n = 8)

अपडेट किया गया टाइमस्टैम्प प्रदर्शित करें -

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

कस्टम व्यावसायिक घंटे का समाप्ति समय प्रदर्शित करें -

print("\nThe end time of the custom business hour...\n",bhOffset.end)

उदाहरण

निम्नलिखित कोड है -

import pandas as pd

# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-9-30 06:50:20')

# Display the Timestamp
print("Timestamp...\n",timestamp)

# Create the BusinessHour Offset
# BusinessHour 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.
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00", n = 8)

# Display the BusinessHour Offset
print("\nBusinessHour Offset...\n",bhOffset)

# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + bhOffset)

# Display the end time of the custom business hour
print("\nThe end time of the custom business hour...\n",bhOffset.end)

आउटपुट

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

Timestamp...
 2021-09-30 06:50:20

BusinessHour Offset...
 <8 * BusinessHours: BH=09:30-18:00>

Updated Timestamp...
 2021-09-30 17:30:00

The end time of the custom business hour...
 (datetime.time(18, 0),)

  1. पायथन - पंडों में टाइमस्टैम्प ऑब्जेक्ट से कार्यदिवस प्राप्त करें

    टाइमस्टैम्प ऑब्जेक्ट से कार्यदिवस प्राप्त करने के लिए, timestamp.weekday() . का उपयोग करें तरीका। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें - import pandas as pd import datetime पंडों में टाइमस्टैम्प सेट करें। टाइमस्टैम्प ऑब्जेक्ट बनाएं timestamp = pd.Timestamp(datetime.datetime(2021, 5, 12)) वर

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

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

  1. पायथन पांडा - टाइमस्टैम्प ऑब्जेक्ट से वर्तमान दिनांक और समय प्राप्त करें

    टाइमस्टैम्प ऑब्जेक्ट से वर्तमान दिनांक और समय प्राप्त करें, timestamp.today() . का उपयोग करें विधि। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें - import pandas as pd import datetime पांडा में टाइमस्टैम्प बनाएं timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10)) टाइमस्टैम्प प्रदर्शित करें pr