Use groupby in Pandas to count things in one column in comparison to another

sparrow

Maybe groupby is the wrong approach. Seems like it should work but I'm not seeing it...

I want to group an event by it's outcome. Here is my DataFrame (df):

Status  Event
SUCCESS Run
SUCCESS Walk
SUCCESS Run
FAILED  Walk

Here is my desired result:

Event   SUCCESS FAILED
Run     2       1
Walk    0       1

I'm trying to make a grouped object but I can't figure out how to call it to display what I want.

grouped = df['Status'].groupby(df['Event'])
piRSquared

I'd do:

df.groupby('Event').Status.value_counts().unstack().fillna(0)

Or use the fill_value argument:

df.groupby('Event').Status.value_counts().unstack(fill_value=0)

enter image description here


Timing

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Use groupby in Pandas to count things in one column in comparison to another

From Dev

GroupBy one column, custom operation on another column of grouped records in pandas

From Dev

pandas get minimum of one column in group when groupby another

From Dev

pandas dataframe: subset by column + groupby another column

From Dev

pandas groupby count string occurrence over column

From Dev

Pandas create new column with count from groupby

From Dev

Adding a 'count' column to the result of a groupby in pandas?

From Dev

pandas groupby count string occurrence over column

From Java

One to Many comparison in pandas two excel column comparison?

From Dev

Pandas: use groupby to count difference between dates

From Dev

Pandas: use groupby to count difference between dates

From Dev

comparison of one column with another column of same row in oracle

From Dev

Pandas Groupby and Sum Only One Column

From Dev

Pandas Groupby and Sum Only One Column

From Dev

How to use groupby in pandas to calculate a percentage / proportion total based on a criteria in another column

From Dev

How can I concatenate date from another column when I use groupby and aggregation in a pandas dataframe

From Dev

Count cells based on a comparison with value in the same row of another column

From Dev

pandas dataframe count uniques with respect to another column

From Java

groupby based on one column and get the sum values in another column

From Dev

groupby and withhold information of one column based on value of another column

From Dev

R: Is there an efficient way to perform groupBy on one column and sum another column?

From Dev

Using Collectors to GroupBy one field, Count and Add another field value

From Dev

How to count groups of one in a column of pandas DataFrame

From Java

Pandas transform dataframe using groupby when count of a string in a column is maximum

From Dev

python pandas: How to simplify the result of groupby('column_name').count()

From Dev

How to get a new dataframe with column count out of groupby function in pandas?

From Dev

Find count of unique column elements after using groupby with pandas

From Dev

Count distinct records in one column with multiple values in another column

From Dev

Count number of values of one column group by value of another column

Related Related

  1. 1

    Use groupby in Pandas to count things in one column in comparison to another

  2. 2

    GroupBy one column, custom operation on another column of grouped records in pandas

  3. 3

    pandas get minimum of one column in group when groupby another

  4. 4

    pandas dataframe: subset by column + groupby another column

  5. 5

    pandas groupby count string occurrence over column

  6. 6

    Pandas create new column with count from groupby

  7. 7

    Adding a 'count' column to the result of a groupby in pandas?

  8. 8

    pandas groupby count string occurrence over column

  9. 9

    One to Many comparison in pandas two excel column comparison?

  10. 10

    Pandas: use groupby to count difference between dates

  11. 11

    Pandas: use groupby to count difference between dates

  12. 12

    comparison of one column with another column of same row in oracle

  13. 13

    Pandas Groupby and Sum Only One Column

  14. 14

    Pandas Groupby and Sum Only One Column

  15. 15

    How to use groupby in pandas to calculate a percentage / proportion total based on a criteria in another column

  16. 16

    How can I concatenate date from another column when I use groupby and aggregation in a pandas dataframe

  17. 17

    Count cells based on a comparison with value in the same row of another column

  18. 18

    pandas dataframe count uniques with respect to another column

  19. 19

    groupby based on one column and get the sum values in another column

  20. 20

    groupby and withhold information of one column based on value of another column

  21. 21

    R: Is there an efficient way to perform groupBy on one column and sum another column?

  22. 22

    Using Collectors to GroupBy one field, Count and Add another field value

  23. 23

    How to count groups of one in a column of pandas DataFrame

  24. 24

    Pandas transform dataframe using groupby when count of a string in a column is maximum

  25. 25

    python pandas: How to simplify the result of groupby('column_name').count()

  26. 26

    How to get a new dataframe with column count out of groupby function in pandas?

  27. 27

    Find count of unique column elements after using groupby with pandas

  28. 28

    Count distinct records in one column with multiple values in another column

  29. 29

    Count number of values of one column group by value of another column

HotTag

Archive