Search code examples
pythonk-means

How to divide data with K-Means clustering in Python


i divided my data to 4 parts using K-Means clustering algorithm. I visualize it , but now i need each cluster as dataframe. Is there any way to do it?


Solution

  • If you use SKlearn for clustering than you can use predict to classify each data point per cluster and save it to a dictionary (as an example).

    Then you can use from_records method from Pandas to convert the dictionary to the DataFrame.