Skip to content

Commit 8e723ab

Browse files
leestottCopilot
andauthored
Update 2-Working-With-Data/08-data-preparation/notebook.ipynb
Co-authored-by: Copilot <[email protected]>
1 parent 5da6e49 commit 8e723ab

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

2-Working-With-Data/08-data-preparation/notebook.ipynb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3919,8 +3919,11 @@
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",

0 commit comments

Comments
 (0)