-2

I want to count the number of occurrences for each input in the column Echantillon. For example:

Echantillon   Classe
1001            0
956             1
9658            2
1001            0
8566            2
956             1

How can this be done using Python?

6
  • 1
    related: stackoverflow.com/questions/29634417/… Commented Sep 5, 2016 at 15:07
  • 1
    Please check value_counts Commented Sep 5, 2016 at 15:08
  • What is desired output? Commented Sep 5, 2016 at 15:09
  • 3
    SO is not a code writing service. As a general rule, I would think that a questioner puts in at least twice as much time into solving the problem themselves as it takes to describe the problem here, and show their working. Commented Sep 5, 2016 at 15:10
  • @EdChum thanks, i see Commented Sep 5, 2016 at 15:13

1 Answer 1

0

If I understand properly then you want total numbers by classes. If it so then you can do it by:

In [9]: df
Out[9]: 
   Echantillon  Classe
0         1001       0
1          956       1
2         9658       2
3         1001       0
4         8566       2
5          956       1

then you can use groupby function:

In [10]: df.groupby(df['Classe']).sum()
Out[10]: 
        Echantillon
Classe             
0              2002
1              1912
2             18224
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.