用法:
Index.get_loc(key, method=None, tolerance=None)
獲取請求標簽的整數位置、切片或布爾掩碼。
- key:標簽
- method:{無,‘pad’/'ffill',‘backfill’/'bfill',‘nearest’},可選
默認值:僅精確匹配。
pad /ffill:如果沒有完全匹配,則查找 PREVIOUS 索引值。
backfill /bfill:如果沒有完全匹配,則使用 NEXT 索引值
最近:如果沒有完全匹配,則使用 NEAREST 索引值。通過首選較大的索引值來打破束縛距離。
- tolerance:int 或 float,可選
與不精確匹配的索引值的最大距離。匹配位置的索引值必須滿足等式
abs(index[loc] - key) <= tolerance
。
- loc:如果是唯一索引則為 int,如果為單調索引則為 slice,否則為 mask
參數:
返回:
例子:
>>> unique_index = pd.Index(list('abc')) >>> unique_index.get_loc('b') 1
>>> monotonic_index = pd.Index(list('abbc')) >>> monotonic_index.get_loc('b') slice(1, 3, None)
>>> non_monotonic_index = pd.Index(list('abcb')) >>> non_monotonic_index.get_loc('b') array([False, True, False, True])
相關用法
- Python pandas.Index.get_level_values用法及代碼示例
- Python pandas.Index.get_indexer_for用法及代碼示例
- Python pandas.Index.get_indexer用法及代碼示例
- Python pandas.Index.value_counts用法及代碼示例
- Python pandas.Index.argmin用法及代碼示例
- Python pandas.Index.is_categorical用法及代碼示例
- Python pandas.Index.to_series用法及代碼示例
- Python pandas.Index.str用法及代碼示例
- Python pandas.Index.to_numpy用法及代碼示例
- Python pandas.Index.is_object用法及代碼示例
- Python pandas.Index.slice_indexer用法及代碼示例
- Python pandas.Index.is_interval用法及代碼示例
- Python pandas.Index.notnull用法及代碼示例
- Python pandas.Index.equals用法及代碼示例
- Python pandas.Index.set_names用法及代碼示例
- Python pandas.Index.searchsorted用法及代碼示例
- Python pandas.Index.duplicated用法及代碼示例
- Python pandas.Index.is_monotonic_increasing用法及代碼示例
- Python pandas.Index.min用法及代碼示例
- Python pandas.Index.is_monotonic_decreasing用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Index.get_loc。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。