Fill emtpy values
Tags: #pandas #snippet #datacleaning #operations
Description: This notebook fill empty values in dataframe columns.
References:
import pandas as pd
import numpy as np
to_fillna
: dict of columns with value to fill
# dict of columns with value to fill
to_fillna = {"team": "Unknown team", "points": 0, "assists": 0, "rebounds": 0}
# create DataFrame
df = pd.DataFrame(
{
"team": ["A", "A", "A", "B", "B", np.NaN],
"points": [11, 7, 8, 10, np.NaN, 13],
"assists": [5, 7, 7, 9, 12, np.NaN],
"rebounds": [np.NaN, 8, 10, 6, 6, np.NaN],
}
)
df
df = df.fillna(to_fillna)
df
Last modified 1d ago