本文簡要介紹
pyspark.pandas.Index.factorize
的用法。用法:
Index.factorize(sort: bool = True, na_sentinel: Optional[int] = - 1) → Tuple[IndexOpsLike, pandas.core.indexes.base.Index]
將對象編碼為枚舉類型或分類變量。
當重要的是識別不同的值時,此方法對於獲取數組的數字表示很有用。
- sort:布爾值,默認為真
- na_sentinel:int 或無,默認 -1
標記“not found”的值。如果沒有,將不會從值的唯一性中刪除 NaN。
- codes:係列或索引
一個係列或索引,它是
uniques
的索引器。uniques.take(codes)
將具有與values
相同的值。- uniques:pd.Index
唯一的有效值。
注意
即使有缺失值
values
,uniques
將要不是包含一個條目。
參數:
返回:
例子:
>>> psser = ps.Series(['b', None, 'a', 'c', 'b']) >>> codes, uniques = psser.factorize() >>> codes 0 1 1 -1 2 0 3 2 4 1 dtype: int32 >>> uniques Index(['a', 'b', 'c'], dtype='object')
>>> codes, uniques = psser.factorize(na_sentinel=None) >>> codes 0 1 1 3 2 0 3 2 4 1 dtype: int32 >>> uniques Index(['a', 'b', 'c', None], dtype='object')
>>> codes, uniques = psser.factorize(na_sentinel=-2) >>> codes 0 1 1 -2 2 0 3 2 4 1 dtype: int32 >>> uniques Index(['a', 'b', 'c'], dtype='object')
對於索引:
>>> psidx = ps.Index(['b', None, 'a', 'c', 'b']) >>> codes, uniques = psidx.factorize() >>> codes Int64Index([1, -1, 0, 2, 1], dtype='int64') >>> uniques Index(['a', 'b', 'c'], dtype='object')
相關用法
- Python pyspark Index.fillna用法及代碼示例
- Python pyspark Index.is_monotonic_decreasing用法及代碼示例
- Python pyspark Index.values用法及代碼示例
- Python pyspark Index.drop_duplicates用法及代碼示例
- Python pyspark Index.value_counts用法及代碼示例
- Python pyspark Index.map用法及代碼示例
- Python pyspark Index.equals用法及代碼示例
- Python pyspark Index.argmin用法及代碼示例
- Python pyspark Index.argmax用法及代碼示例
- Python pyspark Index.item用法及代碼示例
- Python pyspark Index.insert用法及代碼示例
- Python pyspark Index.nlevels用法及代碼示例
- Python pyspark Index.min用法及代碼示例
- Python pyspark Index.copy用法及代碼示例
- Python pyspark Index.difference用法及代碼示例
- Python pyspark Index.to_list用法及代碼示例
- Python pyspark Index.shape用法及代碼示例
- Python pyspark Index.dropna用法及代碼示例
- Python pyspark Index.repeat用法及代碼示例
- Python pyspark Index.notna用法及代碼示例
- Python pyspark Index.has_duplicates用法及代碼示例
- Python pyspark Index.max用法及代碼示例
- Python pyspark Index.astype用法及代碼示例
- Python pyspark Index.to_frame用法及代碼示例
- Python pyspark Index.any用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.Index.factorize。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。