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

PythonPandas-BusinessHourオフセットが正規化されているかどうかを確認します


BusinessHourオフセットが正規化されているかどうかを確認するには、PandasのBusinessHour.normalizeプロパティを使用します。

まず、必要なライブラリをインポートします-

import pandas as pd

パンダでタイムスタンプオブジェクトを設定します-

timestamp = pd.Timestamp('2021-1-1 01:55:30')

BusinessHourオフセットを作成します。 「normalize」パラメータを使用してBusinessHourを正規化しました-

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

更新されたタイムスタンプを表示する-

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

BusinessHourオフセットが正規化されているかどうかを確認します-

print("\nThe BusinessHour Offset is normalized ?\n", bhOffset.normalize)

以下はコードです-

import pandas as pd

# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-1-1 01:55:30')

# 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.
# We have normalized the BusinessHour using the "normalize" parameter
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00", normalize=True)

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

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

# check whether the BusinessHour Offset is normalized or not
print("\nThe BusinessHour Offset is normalized ?\n", bhOffset.normalize)

出力

これにより、次のコードが生成されます-

Timestamp...
 2021-01-01 01:55:30

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

Updated Timestamp...
 2021-01-01 00:00:00

The BusinessHour Offset is normalized ?
 True

  1. Pythonを使用して、指定されたベースで数値の0が連続しているかどうかを確認します

    数値に特定の基数のゼロが連続しているかどうかを確認する必要がある場合は、数値と基数をパラメーターとして受け取り、別のメソッドを使用して、基数が存在するかどうかに応じてYesまたはNoを返すメソッドが定義されます。 以下は同じのデモンストレーションです- 例 def check_consecutive_zero(N, K):    my_result = convert_to_base(N, K)    if (check_n(my_result)):       print("Yes")  

  2. 与えられた番号がPythonでEuclid番号であるかどうかを確認します

    数nがあるとします。 nがユークリッド数であるかどうかを確認する必要があります。私たちが知っているように、ユークリッド数は整数であり、として表すことができます n =P n +1 ここで、は最初のn個の素数の積です。 したがって、入力がn =211のような場合、出力はTrueになります。nはとして表すことができます。 211 =(2×3×5×7)+1 これを解決するには、次の手順に従います- MAX:=10000 primes:=新しいリスト 関数generate_all_primes()を定義します。これには時間がかかります prime:=サイズMAXのリストとT