def replace_nan(df, new_nan_val=None):
    """Replaces all occurrences of NaN values in the DataFrame with a specified
       value.

       Note that this solution seems to result in the DataFrame's columns'
       dtypes being changed to object. (This shouldn't change much due to how
       we handle metadata files, though.)

       Based on the solution described here:
       https://stackoverflow.com/a/14163209/10730311
    """
    return df.where(df.notna(), new_nan_val)
