Python Pandas: How To Group By And Count With A Condition For Every Value In A Column?
I have table like this: d group 1 a 2 b 3 a 4 c 5 f and I like to iterate over values of d and count number of rows that have group=a . Here is what I am doing now, bu
Solution 1:
try:
df['group'].value_counts()['a']
in general, you should NEVER use for loops in pandas. it's inefficient and usually recreating some existing functionality in the package.
Post a Comment for "Python Pandas: How To Group By And Count With A Condition For Every Value In A Column?"