Pandas value_counts() take value from other column

Question:

I have registers about sales where there are a two columns "object" and "value"

   status   value     object  ... amount                                    id payload
2   Pagado  521000      Pollo  ...     15  020d0bb3-91ed-41cb-befb-bb249efb9390     NaN
3   Pagado   38000      Huevo  ...      2  025ea294-50b6-4c40-85a7-aa2780364858     NaN
4   Pagado  250000      Pollo  ...      4  042dcac7-f5ec-44d5-8ddc-1a7cdf17c96e     NaN
5   Pagado    9000      Huevo  ...      1  05e0b188-2554-4491-9a20-33ad9d0e966d     NaN
7   Pagado   38000      Huevo  ...      2  089e5192-4f74-4f63-9a48-d8946dd4d3cb     NaN
9   Pagado  640000   Arriendo  ...      1  0a2c316b-02de-4c0d-b346-4da8b90313ab     NaN
10  Pagado   72000  Gallinita  ...      4  0aaf0b1a-5084-4024-a3e6-05466d82e9fc     NaN
11  Pagado    5000      Badea  ...      5  0ad3d17a-21c0-432b-93a3-9f058934d3e3     NaN
13  Pagado   36000  Gallinita  ...      2  0d9d7985-48f3-4ba4-9659-4e81aeba0d60     NaN
14  Pagado   30000  Gallinita  ...      3  0e13f471-4495-4eaf-878d-b32fe1772b6e     NaN

in "object" are as category Pollo, Huevo, Pescado etc and when I use value_counts() I only get the numbers of time that repeat inside json.

Pollo                  77
Huevo                  76
Gallinita              17
Limon                   5
Arriendo                3

But I want to get the "value" column as sum() belong to each "object" is there a command or I need to separate variables for each category?

example:

Pollo   1600045
Huevo 500089
Gallinita 150000
Arriendo 620000
Asked By: Pife Mena

||

Answers:

If I understand the question right, you just want to sum up the values for each unique "object" column?

This should do the job I think:

df.groupby(['object'])['value'].sum() 
Answered By: ChaoS Adm
print(df.groupby('object', sort=False).value.sum())

For example, if your dataframe is:

    value     object  status
0  521000      Pollo  Pagado
1   38000      Huevo  Pagado
2  250000      Pollo  Pagado
3    9000      Huevo  Pagado
4   38000      Huevo  Pagado
5  640000   Arriendo  Pagado
6   72000  Gallinita  Pagado
7    5000      Badea  Pagado
8   36000  Gallinita  Pagado
9   30000  Gallinita  Pagado

… the result will be the following Series:

object
Pollo        771000
Huevo         85000
Arriendo     640000
Gallinita    138000
Badea          5000
Name: value, dtype: int64
Answered By: constantstranger
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.