I have a pandas DataFrame
like following
clusters 0 [4] 1 [9, 14, 16, 19] 2 [6, 7, 10, 17, 18, 20] 3 [1, 2, 3, 5, 8, 11, 12, 13, 15]
I need to get only the integer values in the cluster column separately. Like following(This can be four lists no need of having another DataFrame
)
0 4 1 9, 14, 16, 19 2 6, 7, 10, 17, 18, 20 3 1, 2, 3, 5, 8, 11, 12, 13, 15
I tried different things. Could not achieve the expected output.
In [36]: clustlist = list(firstclusters.clusters.values) Out[36]: [array([4]), array([ 9, 14, 16, 19]), array([ 6, 7, 10, 17, 18, 20]), array([ 1, 2, 3, 5, 8, 11, 12, 13, 15])] In [37]: np.ravel(clustlist) Out[37]: [array([4]) array([ 9, 14, 16, 19]) array([ 6, 7, 10, 17, 18, 20]) array([ 1, 2, 3, 5, 8, 11, 12, 13, 15])] In [38]: np.hstack(clustlist) Out[38]: [ 4 9 14 16 19 6 7 10 17 18 20 1 2 3 5 8 11 12 13 15]