pandas replace nan with mean code example
Example 1: pandas to convert null values to mean in numeric column
df.fillna(df.mean(), inplace=True)
Example 2: how to fill missing values dataframe with mean
sub2['income'].fillna((sub2['income'].mean()), inplace=True)
Example 3: replace nan in pandas
df['DataFrame Column'] = df['DataFrame Column'].fillna(0)
Example 4: how to replace nan with 0 in pandas
df['product']=df['product'].fillna(0)
df['context']=df['context'].fillna(0)
df
Example 5: pandas replace nan
data["Gender"].fillna("No Gender", inplace = True)
Example 6: replace "-" for nan in dataframe
df.replace(np.nan,0)