Python - Input contains NaN, infinity or a value too large for dtype('float64')
Question: I am new on Python. I am trying to use sklearn.cluster. Here is my code:

    
    
    from sklearn.cluster import MiniBatchKMeans
    
    kmeans=MiniBatchKMeans(n_clusters=2)
    kmeans.fit(df)
    

But I get the following error:

    
    
         50             and not np.isfinite(X).all()):
         51         raise ValueError("Input contains NaN, infinity"
    ---> 52                          " or a value too large for %r." % X.dtype)
    
     ValueError: Input contains NaN, infinity or a value too large for dtype('float64')
    

I checked that the there is no Nan or infinity value. So there is only one
option left. However, my data info tells me that all variables are float64, so
I don't understand where the problem comes from.

    
    
    df.info()
    <class 'pandas.core.frame.DataFrame'>
    Int64Index: 362358 entries, 135 to 4747145
    Data columns (total 8 columns):
    User         362358 non-null float64
    Hour         362352 non-null float64
    Minute       362352 non-null float64
    Day          362352 non-null float64
    Month        362352 non-null float64
    Year         362352 non-null float64
    Latitude     362352 non-null float64
    Longitude    362352 non-null float64
    dtypes: float64(8)
    memory usage: 24.9 MB
    

Thanks a lot,


Answer: I think that [fit()](http://scikit-
learn.org/stable/modules/generated/sklearn.cluster.MiniBatchKMeans.html#sklearn.cluster.MiniBatchKMeans.fit)
accepts only "array-like, shape = [n_samples, n_features]", not pandas
dataframes. So try to pass the values of the dataframe into it as:

    
    
    kmeans=MiniBatchKMeans(n_clusters=2)
    kmeans.fit(df.values)
    

Or shape them in order to run the function correctly. Hope that helps.

