Issue
everyone I was trying to count the number of Yes answered in a column depending on the answer from another previous column to generate pie charts so I'm having problems with this because is giving me counts in boolean like in image below, (This is my codeline):
answers = ['Yes']
hello = (df['Are you okay?']== 'No') &(df['Are yu sad?'].isin(answers))
Actually I just want that the result will be something like this:
Yes
110
EDIT:
This is my result and in red the thing that I want
Solution
If need count values of boolean mask use sum
for processing True
s:
answers = ['Yes']
hello = (df['Are you okay?']== 'No') &(df['Are yu sad?'].isin(answers))
df = pd.DataFrame({answers[0]: hello.sum()})
If ned count Are yu sad?
column by condition df['Are you okay?']== 'No'
use:
df1 = (df.loc[df['Are you okay?']== 'No', 'Are yu sad?']
.value_counts()
.rename_axis('Vals')
.reset_index(name='Count'))
Answered By - jezrael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.