本文整理匯總了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)