train_test_split ValueError: Input contains NaN I tried to do a stratified sampling by way of train_test_split in order to save myself some trouble later. So I wrote the following lines:



from sklearn.model_selection import train_test_split

X=data_df
y=data_df.pop('class')

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.125, stratify=y)




I got the error : 

ValueError: Input contains NaN


Any help is welcome!
Check to see if you have any null or nan values:

X[X.isnull() == True]


Then you have to decide what to do with those nan values. Something that is commonly done is to forward fill in place. 

X.fillna(method = 'ffill', inplace = True)
y.fillna(method = 'ffill', inplace = True)