用法:
DataFrame.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.DataFrame.first用法及代碼示例
- Python cudf.DataFrame.from_pandas用法及代碼示例
- Python cudf.DataFrame.floordiv用法及代碼示例
- Python cudf.DataFrame.floor用法及代碼示例
- Python cudf.DataFrame.from_arrow用法及代碼示例
- Python cudf.DataFrame.mod用法及代碼示例
- Python cudf.DataFrame.isin用法及代碼示例
- Python cudf.DataFrame.rmul用法及代碼示例
- Python cudf.DataFrame.apply用法及代碼示例
- Python cudf.DataFrame.exp用法及代碼示例
- Python cudf.DataFrame.drop用法及代碼示例
- Python cudf.DataFrame.where用法及代碼示例
- Python cudf.DataFrame.median用法及代碼示例
- Python cudf.DataFrame.to_pandas用法及代碼示例
- Python cudf.DataFrame.take用法及代碼示例
- Python cudf.DataFrame.tail用法及代碼示例
- Python cudf.DataFrame.rfloordiv用法及代碼示例
- Python cudf.DataFrame.equals用法及代碼示例
- Python cudf.DataFrame.head用法及代碼示例
- Python cudf.DataFrame.count用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.DataFrame.fillna。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。