本文整理汇总了Python中pandas._libs.hashtable.unique_label_indices方法的典型用法代码示例。如果您正苦于以下问题:Python hashtable.unique_label_indices方法的具体用法?Python hashtable.unique_label_indices怎么用?Python hashtable.unique_label_indices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas._libs.hashtable
的用法示例。
在下文中一共展示了hashtable.unique_label_indices方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decons_obs_group_ids
# 需要导入模块: from pandas._libs import hashtable [as 别名]
# 或者: from pandas._libs.hashtable import unique_label_indices [as 别名]
def decons_obs_group_ids(comp_ids, obs_ids, shape, labels, xnull):
"""
reconstruct labels from observed group ids
Parameters
----------
xnull: boolean,
if nulls are excluded; i.e. -1 labels are passed through
"""
if not xnull:
lift = np.fromiter(((a == -1).any() for a in labels), dtype='i8')
shape = np.asarray(shape, dtype='i8') + lift
if not is_int64_overflow_possible(shape):
# obs ids are deconstructable! take the fast route!
out = decons_group_index(obs_ids, shape)
return out if xnull or not lift.any() \
else [x - y for x, y in zip(out, lift)]
i = unique_label_indices(comp_ids)
i8copy = lambda a: a.astype('i8', subok=False, copy=True)
return [i8copy(lab[i]) for lab in labels]
示例2: test_unique_label_indices
# 需要导入模块: from pandas._libs import hashtable [as 别名]
# 或者: from pandas._libs.hashtable import unique_label_indices [as 别名]
def test_unique_label_indices():
a = np.random.randint(1, 1 << 10, 1 << 15).astype('i8')
left = unique_label_indices(a)
right = np.unique(a, return_index=True)[1]
tm.assert_numpy_array_equal(left, right,
check_dtype=False)
a[np.random.choice(len(a), 10)] = -1
left = unique_label_indices(a)
right = np.unique(a, return_index=True)[1][1:]
tm.assert_numpy_array_equal(left, right,
check_dtype=False)