added code to handle nans in mean across dataframes