snowflake.snowpark.DataFrame.fillna¶
- DataFrame.fillna(value: Union[None, bool, int, float, str, bytearray, Decimal, date, datetime, time, bytes, list, tuple, dict, Dict[str, Union[None, bool, int, float, str, bytearray, Decimal, date, datetime, time, bytes, list, tuple, dict]]], subset: Optional[Union[str, Iterable[str]]] = None) DataFrame[source]¶
Returns a new DataFrame that replaces all null and NaN values in the specified columns with the values provided.
- Parameters:
value – A scalar value or a
dictthat associates the names of columns with the values that should be used to replace null and NaN values in those columns. Ifvalueis adict,subsetis ignored. Ifvalueis an emptydict, the method returns the original DataFrame.subset –
A list of the names of columns to check for null and NaN values. In each case:
If
subsetis not provided orNone, all columns will be included.If
subsetis empty, the method returns the original DataFrame.
Examples:
>>> df = session.create_dataframe([[1.0, 1], [float('nan'), 2], [None, 3], [4.0, None], [float('nan'), None]]).to_df("a", "b") >>> # fill null and NaN values in all columns >>> df.na.fill(3.14).show() --------------- |"A" |"B" | --------------- |1.0 |1 | |3.14 |2 | |3.14 |3 | |4.0 |NULL | |3.14 |NULL | --------------- >>> # fill null and NaN values in column "a" >>> df.na.fill(3.14, subset="a").show() --------------- |"A" |"B" | --------------- |1.0 |1 | |3.14 |2 | |3.14 |3 | |4.0 |NULL | |3.14 |NULL | --------------- >>> # fill null and NaN values in column "a" >>> df.na.fill({"a": 3.14}).show() --------------- |"A" |"B" | --------------- |1.0 |1 | |3.14 |2 | |3.14 |3 | |4.0 |NULL | |3.14 |NULL | --------------- >>> # fill null and NaN values in column "a" and "b" >>> df.na.fill({"a": 3.14, "b": 15}).show() -------------- |"A" |"B" | -------------- |1.0 |1 | |3.14 |2 | |3.14 |3 | |4.0 |15 | |3.14 |15 | --------------
Note
If the type of a given value in
valuedoesn’t match the column data type (e.g. afloatforStringTypecolumn), this replacement will be skipped in this column. Especially,intcan be filled in a column withFloatTypeorDoubleType, butfloatcannot filled in a column withIntegerTypeorLongType.
See also