Issue
I have follwing dataframe:
A | B |
---|---|
3 | 0,0,0 |
4 | 2,0,2 |
56 | 1 |
75 | 2,0 |
52 | 0,0,0 |
How can I count the Total Number of 0,0,0
in column B? In my example above it would be: 2
Thank you!!!
Solution
If your column 'B' consists of lists then this should work:
import pandas as pd
df =pd.DataFrame({'A': [3,4,56,75,52],'B': [[0,0,0],[2,0,2],[1],[2,0],[0,0,0]]})
listWeSearch = [0,0,0]
counter = 0
counter = len([counter+1 for i in range(len(df)) if df.iloc[i]['B'] == listWeSearch])
Otherwise if the values of 'B' the other solutions proposed should work!
Answered By - apostolos ts
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.