當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cudf.IntervalIndex.get_loc用法及代碼示例

用法:

IntervalIndex.get_loc(key, method=None, tolerance=None)

獲取請求標簽的整數位置、切片或布爾掩碼。

參數

key標簽
method{無,‘pad’/'fill',‘backfill’/'bfill',‘nearest’},可選
  • 默認值:僅完全匹配。
  • pad /ffill:如果沒有完全匹配,則查找 PREVIOUS 索引值。
  • backfill /bfill:如果沒有完全匹配,則使用 NEXT 索引值。
  • 最近:如果沒有完全匹配,則使用 NEAREST 索引值。通過首選較大的索引值來打破束縛距離。
toleranceint 或 float,可選

與不精確匹配的索引值的最大距離。匹配位置的索引值必須滿足等式 abs(index[loc] - key) <= tolerance

返回

int 或 slice 或 boolean 掩碼
  • 如果結果是唯一的,則返回整數索引
  • 如果 index 是單調的,則 loc 作為切片對象返回
  • 否則,返回一個布爾掩碼

例子

>>> unique_index = cudf.Index(list('abc'))
>>> unique_index.get_loc('b')
1
>>> monotonic_index = cudf.Index(list('abbc'))
>>> monotonic_index.get_loc('b')
slice(1, 3, None)
>>> non_monotonic_index = cudf.Index(list('abcb'))
>>> non_monotonic_index.get_loc('b')
array([False,  True, False,  True])
>>> numeric_unique_index = cudf.Index([1, 2, 3])
>>> numeric_unique_index.get_loc(3)
2

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.IntervalIndex.get_loc。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。