用法:
Series.fillna(value=None, method=None, axis=None, inplace=False, limit=None)
用
value
或指定的method
填充空值。- value:標量,Series-like 或字典
用於填充空值的值。如果Series-like,空值填充對應索引中的值。 dict 可用於提供不同的值來填充不同列中的空值。不能與
method
一起使用。- method:{‘ffill’, ‘bfill’},默認無
用於填充 DataFrame 或係列中的空值的方法。
ffill
將最後一個非空值向前傳播到下一個非空值。bfill
使用下一個非空值向後傳播。不能與value
一起使用。
- result:DataFrame
複製並填充空值。
參數:
返回:
例子:
>>> import cudf >>> df = cudf.DataFrame({'a': [1, 2, None], 'b': [3, None, 5]}) >>> df a b 0 1 3 1 2 <NA> 2 <NA> 5 >>> df.fillna(4) a b 0 1 3 1 2 4 2 4 5 >>> df.fillna({'a': 3, 'b': 4}) a b 0 1 3 1 2 4 2 3 5
fillna
在 Series 對象上:>>> ser = cudf.Series(['a', 'b', None, 'c']) >>> ser 0 a 1 b 2 <NA> 3 c dtype: object >>> ser.fillna('z') 0 a 1 b 2 z 3 c dtype: object
fillna
還可以支持就地操作:>>> ser.fillna('z', inplace=True) >>> ser 0 a 1 b 2 z 3 c dtype: object >>> df.fillna({'a': 3, 'b': 4}, inplace=True) >>> df a b 0 1 3 1 2 4 2 3 5
fillna
用填充指定method
>>> ser = cudf.Series([1, None, None, 2, 3, None, None]) >>> ser.fillna(method='ffill') 0 1 1 1 2 1 3 2 4 3 5 3 6 3 dtype: int64 >>> ser.fillna(method='bfill') 0 1 1 2 2 2 3 2 4 3 5 <NA> 6 <NA> dtype: int64
相關用法
- Python cudf.Series.first用法及代碼示例
- Python cudf.Series.from_pandas用法及代碼示例
- Python cudf.Series.floordiv用法及代碼示例
- Python cudf.Series.from_categorical用法及代碼示例
- Python cudf.Series.from_masked_array用法及代碼示例
- Python cudf.Series.factorize用法及代碼示例
- Python cudf.Series.floor用法及代碼示例
- Python cudf.Series.from_arrow用法及代碼示例
- Python cudf.Series.ceil用法及代碼示例
- Python cudf.Series.update用法及代碼示例
- Python cudf.Series.max用法及代碼示例
- Python cudf.Series.head用法及代碼示例
- Python cudf.Series.reindex用法及代碼示例
- Python cudf.Series.interleave_columns用法及代碼示例
- Python cudf.Series.min用法及代碼示例
- Python cudf.Series.nlargest用法及代碼示例
- Python cudf.Series.to_frame用法及代碼示例
- Python cudf.Series.mask用法及代碼示例
- Python cudf.Series.notnull用法及代碼示例
- Python cudf.Series.isnull用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.Series.fillna。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。