Counting matches won by teams This script counts how many matches were won by the team with a first half, second half, and full game time of possession differential advantage. 

The data is stored in a pandas data frame:




   Points  H1  H2  Total
0      36  46  50     96
1      -5  16  18     34
2      47  12  65     77
3      12  79  13     92
4      -7  53 -64    -11
5      36  -3 -55    -58
6       9  27  87    114
7      17  66 -10     56



The script counts matches won by a team with a positive time of possession differential as well as matches lost by a team with a negative time of possession differential.

From the above example data, matches 0,2,3,4,6,7 would be selected for total wins because the team with the possession advantage won or the team with the possession disadvantage lost.

Match 1 was lost by the team with more total possession. Match 5 was won by the team with less total possession.

This snippet finds the winners for first half, second half, and the total match time.



total_win = ((poss_diff['Points'] &gt; 0) &amp; (poss_diff['Total'] &gt; 0) | (poss_diff['Points'] &lt; 0) &amp; (poss_diff['Total'] &lt; 0))
h1_win = ((poss_diff['Points'] &gt; 0) &amp; (poss_diff['H1'] &gt; 0) | (poss_diff['Points'] &lt; 0) &amp; (poss_diff['H1'] &lt; 0))
h2_win = ((poss_diff['Points'] &gt; 0) &amp; (poss_diff['H2'] &gt; 0) | (poss_diff['Points'] &lt; 0) &amp; (poss_diff['H2'] &lt; 0))
print len(poss_diff[total_win])
print len(poss_diff[h1_win])
print len(poss_diff[h2_win])


Is there a more Pythonic way to calculate and store the results using lambda, applymap, or another function?
condition a &gt; 0 and b &gt; 0 or a &lt; 0 and b &lt; 0 often can be write as a * b &gt; 0 (it depends on multiply cost)
maybe you can use it something as total_win = ( poss_diff.Points * poss_diff.Total &gt; 0 )
len(poss_diff[total_win]) can be translate to total_win.sum()