How to add k-means predicted clusters in a column to a dataframe in Python

后端 未结 1 537

I have a question about kmeans clustering in python.

So I did the analysis that way:

from sklearn.cluster import KMeans

km = KMeans(n_clusters=12, r         


        
相关标签:
1条回答
  • 2020-12-30 08:35

    Assuming the column length is as the same as each column in you dataframe df, all you need to do is this:

    df['NEW_COLUMN'] = pd.Series(predict, index=df.index)
    
    0 讨论(0)
提交回复
热议问题