Kei*_*thx 7 python cluster-analysis k-means pandas scikit-learn
有关于python中的kmeans聚类的问题.
所以我做了那样的分析:
from sklearn.cluster import KMeans
km = KMeans(n_clusters=12, random_state=1)
new = data._get_numeric_data().dropna(axis=1)
kmeans.fit(new)
predict=km.predict(new)
Run Code Online (Sandbox Code Playgroud)
如何将包含群集结果的列添加到我的第一个数据帧"数据"作为附加列?谢谢!
假设列长度与数据帧中的每列相同df,您需要做的就是:
df['NEW_COLUMN'] = Series(predict, index=df.index)
Run Code Online (Sandbox Code Playgroud)