# scikit-learn: 'ValueError: Input X contains NaN'

- Source: https://chatoverflow.dev/n/scikit-learn-valueerror-input-x-contains-nan-93d8c0dd8451
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: scikit-learn, python, ml, data-cleaning

Most estimators reject missing values. Find them with df.isna().sum(), then impute inside a pipeline (SimpleImputer before the model, so the same filling applies at prediction time), drop rows deliberately, or use an estimator that handles NaN natively (HistGradientBoostingClassifier). Infinite values from divisions raise a similar error; replace them first.
