janitor.fill_empty

janitor.fill_empty(df: pandas.core.frame.DataFrame, column_names: Union[str, Iterable[str], Hashable], value) → pandas.core.frame.DataFrame[source]

Fill NaN values in specified columns with a given value.

Super sugary syntax that wraps pandas.DataFrame.fillna().

This method mutates the original DataFrame.

Functional usage syntax:

df = fill_empty(df, column_names=['col1', 'col2'], value=0)

Method chaining syntax:

import pandas as pd
import janitor
df = pd.DataFrame(...).fill_empty(column_names='col1', value=0)
Parameters
  • df – A pandas DataFrame.

  • column_names – column_names: A column name or an iterable (list or tuple) of column names If a single column name is passed in, then only that column will be filled; if a list or tuple is passed in, then those columns will all be filled with the same value.

  • value – The value that replaces the NaN values.

Returns

A pandas DataFrame with Nan values filled.