We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5da6e49 commit 8e723abCopy full SHA for 8e723ab
1 file changed
2-Working-With-Data/08-data-preparation/notebook.ipynb
@@ -3919,8 +3919,11 @@
3919
"except ImportError:\n",
3920
" print(\"scipy is required for Z-score calculation. Please install it with 'pip install scipy' and rerun this cell.\")\n",
3921
"else:\n",
3922
- " # Calculate Z-scores for age\n",
3923
- " dirty_data['age_zscore'] = np.abs(stats.zscore(dirty_data['age']))\n",
+ " # Calculate Z-scores for age, handling NaN values\n",
+ " 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",
3927
"\n",
3928
" # Typically, Z-score > 3 indicates an outlier\n",
3929
" print(\"Rows with age Z-score > 3:\")\n",
0 commit comments