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

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


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

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

import datetime
import pandas as pd

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

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

BusinessDayオフセットを作成します。 BusinessDayはDateOffsetサブクラスです。 「normalize」パラメータを使用してBusinessDayを正規化しました-

bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(hours = 8, minutes = 10), normalize=True)

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

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

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

print("\nThe BusinessDay Offset is normalized..\n", bdOffset.normalize)

以下はコードです-

import datetime
import pandas as pd

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

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

# Create the BusinessDay Offset
# BusinessDay is the DateOffset subclass
# We have normalized the BusinessDay using the "normalize" parameter
bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(hours = 8, minutes = 10), normalize=True)

# Display the BusinessDay Offset
print("\nBusinessDay Offset...\n",bdOffset)

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

# return the frequency applied on the given BusinessDay object as a string
print("\nFrequency on the given BusinessDay Offset...\n",bdOffset.freqstr)

# return the name of the frequency applied on the given BusinessDay object
print("\nThe name of the frequency on the BusinessDay object..\n", bdOffset.name)

# check whether the BusinessDay Offset is normalized or not
print("\nThe BusinessDay Offset is normalized..\n", bdOffset.normalize)

出力

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

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

BusinessDay Offset...
 <BusinessDay: offset=datetime.timedelta(seconds=29400)>

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

Frequency on the given BusinessDay Offset...
 B+8H10Min

The name of the frequency on the BusinessDay object..
 B

The BusinessDay 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