本文整理汇总了Python中pandas.tseries.index.Index.get_loc方法的典型用法代码示例。如果您正苦于以下问题:Python Index.get_loc方法的具体用法?Python Index.get_loc怎么用?Python Index.get_loc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.tseries.index.Index
的用法示例。
在下文中一共展示了Index.get_loc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_loc
# 需要导入模块: from pandas.tseries.index import Index [as 别名]
# 或者: from pandas.tseries.index.Index import get_loc [as 别名]
def get_loc(self, key, method=None, tolerance=None):
"""
Get integer location for requested label
Returns
-------
loc : int
"""
try:
return self._engine.get_loc(key)
except KeyError:
if is_integer(key):
raise
try:
asdt, parsed, reso = parse_time_string(key, self.freq)
key = asdt
except TypeError:
pass
try:
key = Period(key, freq=self.freq)
except ValueError:
# we cannot construct the Period
# as we have an invalid type
raise KeyError(key)
try:
ordinal = tslib.iNaT if key is tslib.NaT else key.ordinal
return Index.get_loc(self, ordinal, method, tolerance)
except KeyError:
raise KeyError(key)
示例2: get_loc
# 需要导入模块: from pandas.tseries.index import Index [as 别名]
# 或者: from pandas.tseries.index.Index import get_loc [as 别名]
def get_loc(self, key, method=None):
"""
Get integer location for requested label
Returns
-------
loc : int
"""
try:
return self._engine.get_loc(key)
except KeyError:
if is_integer(key):
raise
try:
asdt, parsed, reso = parse_time_string(key, self.freq)
key = asdt
except TypeError:
pass
key = Period(key, self.freq)
try:
return Index.get_loc(self, key.ordinal, method=method)
except KeyError:
raise KeyError(key)