I have the following df,
data = [['Male', 'Agree'], ['Male', 'Agree'], ['Male', 'Disagree'], ['Female','Neutral']]
df = pd.DataFrame(data, columns = ['Sex', 'Opinion'])
df
& would like to get the total number of Male who either Agree or Disagree. I expect the answer to be 3 but instead get 9.
sum([True for x in df['Opinion'] for y in df['Sex'] if x in ['Agree','Disagree'] if y=='Male' ]
I have done this through other methods and I'm trying to understand list comprehension better.