用法:
MultiIndex.get_loc(key, method=None, tolerance=None)
獲取標簽或標簽元組的位置。
該位置以整數/切片或布爾掩碼的形式返回。
- key:標簽或標簽元組(每個級別一個)
- method:None
- loc:int,切片對象或布爾掩碼
- 如果索引是唯一的,則搜索結果是唯一的,返回一個 int.
- 如果 index 是單調的,則 index 作為切片對象返回。
- 否則, cudf 會盡最大努力將搜索結果轉換為切片對象,如果不這樣做,將返回一個布爾掩碼。請注意,在某些情況下,這可能會偏離 Pandas 的行為。
參數:
返回:
例子:
>>> import cudf >>> mi = cudf.MultiIndex.from_tuples( ... [('a', 'd'), ('b', 'e'), ('b', 'f')]) >>> mi.get_loc('b') slice(1, 3, None) >>> mi.get_loc(('b', 'e')) 1 >>> non_monotonic_non_unique_idx = cudf.MultiIndex.from_tuples( ... [('c', 'd'), ('b', 'e'), ('a', 'f'), ('b', 'e')]) >>> non_monotonic_non_unique_idx.get_loc('b') # differ from pandas slice(1, 4, 2)
Pandas 兼容性說明
多索引。get_loc
該函數的返回類型可能與 Pandas 提供的方法不同。如果索引既不是按字典順序排序也不是唯一的,則盡最大努力將找到的索引強製轉換為切片。例如:
>>> import pandas as pd >>> import cudf >>> x = pd.MultiIndex.from_tuples([ ... (2, 1, 1), (1, 2, 3), (1, 2, 1), ... (1, 1, 1), (1, 1, 1), (2, 2, 1), ... ]) >>> x.get_loc(1) array([False, True, True, True, True, False]) >>> cudf.from_pandas(x).get_loc(1) slice(1, 5, 1)
相關用法
- Python cudf.MultiIndex.from_arrow用法及代碼示例
- Python cudf.MultiIndex.levels用法及代碼示例
- Python cudf.MultiIndex.droplevel用法及代碼示例
- Python cudf.MultiIndex.codes用法及代碼示例
- Python cudf.MultiIndex.from_frame用法及代碼示例
- Python cudf.MultiIndex.from_product用法及代碼示例
- Python cudf.MultiIndex.from_tuples用法及代碼示例
- Python cudf.MultiIndex用法及代碼示例
- Python cudf.core.column.string.StringMethods.is_vowel用法及代碼示例
- Python cudf.Series.ceil用法及代碼示例
- Python cudf.core.column.string.StringMethods.endswith用法及代碼示例
- Python cudf.Series.update用法及代碼示例
- Python cudf.DataFrame.mod用法及代碼示例
- Python cudf.DataFrame.isin用法及代碼示例
- Python cudf.core.column.string.StringMethods.title用法及代碼示例
- Python cudf.DataFrame.rmul用法及代碼示例
- Python cudf.Series.max用法及代碼示例
- Python cudf.DatetimeIndex.dayofweek用法及代碼示例
- Python cudf.DataFrame.apply用法及代碼示例
- Python cudf.core.column.string.StringMethods.contains用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.MultiIndex.get_loc。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。