Using value_counts with conditions (datetime)

Viewed 44

I am trying to keep only true values of my column, here is the code and output:


 self.mask = self.data['Date'].apply(self.in_range, args=(user_start, user_stop))

 def evaluate_error(self):
        err_count = self.data.groupby([self.mask, 'Résultat']).size()
        print(err_count)
        print('')

output: 

Date   Résultat
False  0           85
       51           1
       55           1
       656          2
True   0           10
       55           1


1 Answers

You can filter values after groupby.size:

err_count = self.data.groupby([self.mask, 'Résultat']).size().loc[True]

Or before, then is possible use Series.value_counts:

err_count = self.data.loc[self.mask, 'Résultat'].value_counts() 

err_count = self.data.loc[self.mask, 'Résultat'].groupby('Résultat').size()
Related