PythonPandas-間隔が右側で開いているかどうかを確認します
間隔が右側で開いているかどうかを確認するには、 interval.open_rightを使用します 財産。まず、必要なライブラリをインポートします-
import pandas as pd
値が「どちらでもない」の「closed」パラメーターを使用して設定されたオープン間隔。開区間(角括弧で示される数学)にはその端点が含まれていません。つまり、開区間[0、5]は条件0
interval = pd.Interval(5, 20, closed='neither')
間隔を表示する
print("Interval...\n",interval)
右側でインターバルが開いているかどうかを確認します
print("\nCheck if the interval is open on the right side...\n",interval.open_right)
例
以下はコードです
import pandas as pd # Open interval set using the "closed" parameter with value "neither" # An open interval (in mathematics denoted by square brackets) does not contains its endpoints, # i.e. the open interval [0, 5] is characterized by the conditions 0 < x < 5. interval = pd.Interval(5, 20, closed='neither') # display the interval print("Interval...\n",interval) # the left bound print("\nThe left bound for the Interval...\n",interval.left) # the right bound print("\nThe right bound for the Interval...\n",interval.right) # display the interval length print("\nInterval length...\n",interval.length) # check whether the interval is open on the right side print("\nCheck if the interval is open on the right side...\n",interval.open_right)>
出力
これにより、次のコードが生成されます
Interval... (5, 20) The left bound for the Interval... 5 The right bound for the Interval... 20 Interval length... 15 Check if the interval is open on the right side... True
-
PythonPandas-IntervalArray内の各間隔の適切なエンドポイントをインデックスとして返します
IntervalArray内の各間隔の正しい端点をインデックスとして返すには、 array.rightを使用します プロパティ。 まず、必要なライブラリをインポートします- import pandas as pd 2つのIntervalオブジェクトを作成します- interval1 = pd.Interval(10, 25) interval2 = pd.Interval(15, 70) 間隔を表示する- print("Interval1...\n",interval1) print("Interval2...\n",interval2) Int
-
PythonPandas-間隔の正しい境界を取得します
間隔の正しい範囲を取得するには、 interval.rightを使用します 財産。まず、必要なライブラリをインポートします- import pandas as pd 時間間隔を作成するための境界としてタイムスタンプを使用します。値が「right」の「closed」パラメータを使用して設定された閉じた間隔- interval = pd.Interval(pd.Timestamp('2020-01-01 00:00:00'), pd.Timestamp('2021-01-01 00:00:00'), closed='left') 正しい境界