How to create new feature based on clustering result
To do clustering you can use sklearn's KMeans Clustering function - sklearn.cluster.KMeans with n_clusters=3 and other parameters as default. This will give you 3 clusters. After you have trained your model you can use the .labels_ attribute of the trained model to classify every example. You can do this in the following way:

&gt;&gt;&gt; from sklearn.cluster import KMeans
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; X = np.array([[1, 2], [1, 4], [1, 0],
...               [10, 2], [10, 4], [10, 0]])
&gt;&gt;&gt; kmeans = KMeans(n_clusters=2, random_state=0).fit(X)
&gt;&gt;&gt; kmeans.labels_
array([1, 1, 1, 0, 0, 0], dtype=int32)


To create a new column based on category cluster you can simply add the kmeans.labels_ array as a column to your original dataframe:

&gt;&gt;&gt; df['categories'] = kmeans.labels_