File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
2-Working-With-Data/08-data-preparation Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change 39193919 " except ImportError:\n " ,
39203920 " print(\" scipy is required for Z-score calculation. Please install it with 'pip install scipy' and rerun this cell.\" )\n " ,
39213921 " else:\n " ,
3922- " # Calculate Z-scores for age\n " ,
3923- " dirty_data['age_zscore'] = np.abs(stats.zscore(dirty_data['age']))\n " ,
3922+ " # Calculate Z-scores for age, handling NaN values\n " ,
3923+ " age_nonan = dirty_data['age'].dropna()\n " ,
3924+ " zscores = np.abs(stats.zscore(age_nonan))\n " ,
3925+ " dirty_data['age_zscore'] = np.nan\n " ,
3926+ " dirty_data.loc[age_nonan.index, 'age_zscore'] = zscores\n " ,
39243927 " \n " ,
39253928 " # Typically, Z-score > 3 indicates an outlier\n " ,
39263929 " print(\" Rows with age Z-score > 3:\" )\n " ,
You can’t perform that action at this time.
0 commit comments