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

PythonPandas-指定されたCustomBusinessHourが固定されているかどうかを確認します


指定されたCustomBusinessHourがアンカーされているかどうかを確認するには、PandasのCustomBusinessHour.is_anchored()メソッドを使用します。

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

import pandas as pd

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

timestamp = pd.Timestamp('2021-11-14 05:20:30')

CustomBusinessHourオフセットを作成します。 CustomBusinessHourはDateOffsetサブクラスです-

cbhOffset = pd.tseries.offsets.CustomBusinessHour(start="09:30", end = "18:30")

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

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

CustomBusinessHourが固定されているかどうかを確認します-

print("\nCheck whether the CustomBusinessHour is anchored...\n", cbhOffset.is_anchored())

以下はコードです-

import pandas as pd

# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-11-14 05:20:30')

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

# Create the CustomBusinessHour Offset
# CustomBusinessHour 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.
cbhOffset = pd.tseries.offsets.CustomBusinessHour(start="09:30", end = "18:30")

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

# Check whether the CustomBusinessHour is anchored
print("\nCheck whether the CustomBusinessHour is anchored...\n", cbhOffset.is_anchored())

出力

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

Timestamp...
 2021-11-14 05:20:30

CustomBusinessHour Offset...
 <CustomBusinessHour: CBH=09:30-18:30>

Updated Timestamp...
 2021-11-15 10:30:00

Check whether the CustomBusinessHour is anchored...
 True

  1. 指定された文字列がパングラムであるかどうかを確認するPythonプログラム

    この記事では、特定の問題ステートメントを解決するための解決策とアプローチについて学習します。 問題の説明 文字列入力が与えられた場合、その文字列がパングラムであるかどうかを確認するPythonプログラムを生成する必要があります。 パングラムは、英語のアルファベットコレクションのすべての文字を含む文/一連の単語です。 では、問題を解決する方法を見てみましょう 入力文字列に存在する各文字が、手動で宣言するアルファベットセットに属しているかどうかをチェックするループを使用します。 上記のアプローチの実装は、-によって与えられます。 例 import string def ispangram

  2. 指定された配列が単調であるかどうかを確認するPythonプログラム

    この記事では、特定の問題ステートメントを解決するための解決策とアプローチについて学習します。 問題の説明 n個の整数を含む配列入力Arrが与えられます。入力配列が本質的に単調であるかどうかを確認する必要があります。 アレイが継続的に増加または継続的に減少している場合、そのアレイは本質的に単調であると言われます。 数学的に すべてのi<=j、の場合、配列Aは継続的に増加します。 A[i] <= A[j]. すべてのi<=j、の場合、配列Aは継続的に減少しています。 A[i] >= A[j]. ここでは、隣接するすべての要素が上記の条件のいずれかを満たしているかどうかを確