Clustering on dataframe values based on ,condition

Viewed 18
Name   Age   Status
Xenon    3    Bot
Carrie   16   Human
Argon    6    Bot
Carol    7    Human
Neon     5    Human

I want to cluster them based on status, if its Bot then cluster 1, if Human then cluster 2, then visualize it.

Expected Output:
-   Name   Age   Status   Bocluster
    Xenon    3    Bot      Cluster 1
    Carrie   16   Human    Cluster 2
    Argon    6    Bot      Cluster 1
    Carol    7    Human    Cluster 2
    Neon     5    Human    Cluster 2

How can i achieve this? I tried using K means , but i am not sure whether its a right approach.Any help is highly appreciated Thank you

1 Answers

You don't need a clustering algorithm for that.

cluster_decision = (df["Status"] == "Human").astype(int)
cluster_col = cluster_decision.map(lambda clus: "Cluster " + str(clus+1))

First, the Status is used to determine if the entry is human as a boolean, which is converted to an int. Next, the column is mapped to the prettier representation that you expect. Lastly, you would have to add this column to your data frame (not shown here).

Related