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

PythonPandas-指定されたラベルに対応する左側のスライス境界を計算します


指定されたラベルに対応する左側のスライス境界を計算するには、 index.get_slice_bound()を使用します 。 サイドを設定します へのパラメータ 。

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

import pandas as pd

パンダインデックスの作成-

index = pd.Index([10, 20, 30, 40, 50, 60, 70])

パンダのインデックスを表示する-

print("Pandas Index...\n",index)

左側のスライスをバインドします。 「side」パラメータが「left」に設定されている場合、指定されたラベルの左側のスライス境界を返します

print("\nGet the left slice bound...\n",index.get_slice_bound(30, side='left', kind ='getitem'))

以下はコードです-

import pandas as pd

# Creating Pandas index
index = pd.Index([10, 20, 30, 40, 50, 60, 70])

# Display the Pandas index
print("Pandas Index...\n",index)

# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)

# Get the left slice bound
# Returns the left slice bound of given label if "side" parameter is set to "left"
print("\nGet the left slice bound...\n", index.get_slice_bound(30, side='left', kind ='getitem'))
に設定

出力

これにより、次の出力が生成されます-

Pandas Index...
Int64Index([10, 20, 30, 40, 50, 60, 70], dtype='int64')

Number of elements in the index...
7

Get the left slice bound...
2

  1. Python-PandasIndexがフローティングタイプかどうかを確認します

    Pandas Indexがフローティングタイプであるかどうかを確認するには、 index.is_floating()を使用します パンダのメソッド。まず、必要なライブラリをインポートします- import pandas as pd パンダインデックスの作成- index = pd.Index([5.7, 6.8, 10.5, 20.4, 25.6, 30.8, 40.5, 50.2]) パンダのインデックスを表示する- print("Pandas Index...\n",index) インデックス値に浮動小数点数しかないかどうかを確認します- print("

  2. pythonPandas-IntervalArrayの各間隔の左端をインデックスとして返します

    IntervalArrayの各間隔の左端をインデックスとして返すには、 array.leftを使用します プロパティ。 まず、必要なライブラリをインポートします- import pandas as pd 2つのIntervalオブジェクトを作成します- nterval1 = pd.Interval(10, 25) interval2 = pd.Interval(15, 70) 間隔を表示する- print("Interval1...\n",interval1) print("Interval2...\n",interval2) Intervalオ