Python
 Computer >> コンピューター >  >> プログラミング >> Python

PythonPandas-BusinessHourオフセットオブジェクトからカスタム営業時間の終了時刻を24時間形式で表示します


BusinessHourオフセットオブジェクトからカスタム営業時間の終了時刻を24時間形式で表示するには、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. Pythonパンダ-UTCオフセット時間を取得

    UTCオフセット時間を取得するには、 timestamp.utcoffset()を使用します 。まず、必要なライブラリをインポートします- import pandas as pd タイムスタンプの作成 timestamp = pd.Timestamp('2021-10-16T15:12:34.261811624', tz='UTC') UTCの日時を含む新しいタイムスタンプ timestamp.utcnow() UTCオフセット時間を取得する timestamp.utcoffset() 例 以下はコードです import pandas as pd

  2. PythonPandas-Timestampオブジェクトから現在の日付と時刻を取得します

    Timestampオブジェクトから現在の日付と時刻を取得し、 timestamp.today()を使用します メソッド。 まず、必要なライブラリをインポートします- import pandas as pd import datetime パンダでタイムスタンプを作成する timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10)) タイムスタンプを表示する print("Timestamp: ", timestamp) 現在の日付と時刻を取得する res = timestamp.today() 例 以下はコ