set nan values to mean pandas code example Example 1: how to replace nan values with 0 in pandas df.fillna(0) Example 2: how to fill nan values with mean in pandas df.fillna(df.mean())