Pythonパンダ-間隔の長さを取得します
間隔の長さを取得するには、 interval.lengthを使用します 財産。まず、必要なライブラリをインポートします-
import pandas as pd
値が「どちらでもない」の「closed」パラメーターを使用して設定されたオープン間隔。開区間(角括弧で示される数学)にはその端点が含まれていません。つまり、開区間[0、5]は条件0
interval = pd.Interval(5, 20, closed='neither')
間隔の長さを表示する
print("\nInterval length...\n",interval.length)
例
以下はコードです
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)
出力
これにより、次のコードが生成されます
Interval... (5, 20) The left bound for the Interval... 5 The right bound for the Interval... 20 Interval length... 15
-
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') 正しい境界
-
Pythonで文字列の長さを取得するにはどうすればよいですか?
Pythonには、複合オブジェクトの長さを指定するlen()というメソッドがあります。文字列の長さを取得するには、文字列をlen()呼び出しに渡すだけです。たとえば、 print(len('abcdefghijklmnopqrstuvwxyz')) 出力 26