pandas.factorize

官网地址https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.factorize.html

pandas.factorize

将Series中的相同的标称型映射为相同的index

pandas.factorize(valuessort=Falsena_sentinel=- 1size_hint=Nonedropna=True)[source]

Encode the object as an enumerated type or categorical variable.

This method is useful for obtaining a numeric representation of an array when all that matters is identifying distinct values. factorize is available as both a top-level function pandas.factorize(), and as a method Series.factorize() and Index.factorize().

Parameters

valuessequence

A 1-D sequence. Sequences that aren’t pandas objects are coerced to ndarrays before factorization.

sortbool, default False

Sort uniques and shuffle codes to maintain the relationship.

na_sentinelint, default -1

Value to mark “not found”.

size_hintint, optional

Hint to the hashtable sizer.

Returns

codesndarray

An integer ndarray that’s an indexer into uniques. uniques.take(codes) will have the same values as values.

uniquesndarray, Index, or Categorical

The unique valid values. When values is Categorical, uniques is a Categorical. When values is some other pandas object, an Index is returned. Otherwise, a 1-D ndarray is returned.

Note

Even if there’s a missing value in values, uniques will not contain an entry for it.

See also

cut

Discretize continuous-valued array.

unique

Find the unique value in an array.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值