efficiently replace in pandas dataframe code example Example: pandas dataframe replace inf df.replace([np.inf, -np.inf], np.nan)