Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to count occurrences per label?

How can I count the 1’s and 0’s in column [1] per unique class in column [0]?

labels = []

estimator = est.fit(X.iloc[:,1:])
labels.append(estimator.labels_)
labels.append(O)
labels = pd.DataFrame(np.array(labels).transpose())
labels.iloc[:,1] = (labels.iloc[:,1] > 5).astype(int) # Binary GOS-E

x = np.array(labels.iloc[:,1]).reshape(-1, 1)
y = np.array(labels.iloc[:,0])

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df.groupby may suit your needs.

Group by class in column 0, and aggregate using ‘sum’, which works because only 1s will be ‘counted’

df.groupby(df.iloc[:,0]).agg('sum') or df.groupby(df.iloc[:,0]).sum() should work. You can also use df['name of column 0'] instead of df.iloc[:,0].

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading