Count num of occurrences by value in a Pandas series

69 Views Asked by At

I have a Pandas series like the following one:

    id    val
    id_1   1
    id_2   1
    id_3   2
    id_4   2
    id_5   1
    ...

I want to count the number of ids with value 1, 2, 3, etc. Something like this:

    value n_ocurr 
    1     102
    2     20
    3     40 
    ...

Is there an easy way to do this? (hopefully without converting the series to a pd.DataFrame)

0

There are 0 best solutions below