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

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


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

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

import pandas as pd

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

timestamp = pd.Timestamp('2021-10-25 08:35:10')

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

cbhOffset = pd.tseries.offsets.CustomBusinessHour(n = 3, weekmask = 'Mon Tue Wed Fri Sat' ,normalize=True)

タイムスタンプにオフセットを追加し、更新されたタイムスタンプを表示します-

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

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

print("\nThe CustomBusinessHour Offset is normalized ?\n", cbhOffset.normalize)

以下はコードです-

import pandas as pd

# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-10-25 08:35:10')

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

# Create the CustomBusinessHour Offset
# CustomBusinessHour is the DateOffset subclass
# Weekmask of valid business days
# We have normalized the CustomBusinessDay using the "normalize" parameter
cbhOffset = pd.tseries.offsets.CustomBusinessHour(n = 3, weekmask = 'Mon Tue Wed Fri Sat',normalize=True)

# 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)

# Return frequency applied on the given CustomBusinessHour Offset object as a string
print("\nFrequency applied on the given CustomBusinessHour Offset object...\n",cbhOffset.freqstr)

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

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

出力

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

Timestamp...
 2021-10-25 08:35:10

CustomBusinessHour Offset...
 <3 * CustomBusinessHours: CBH=09:00-17:00>

Updated Timestamp...
 2021-10-25 00:00:00

Frequency applied on the given CustomBusinessHour Offset object...
 3CBH

The name of the frequency on the CustomBusinessHour object..
 CBH

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