Calculation on multiple hits in a panda data frame : <p>Hi, I want to know if it's possible to do the following calculation in a panda data frame in python. I have a single data frame with the below columns</p>
<p>City | Zone | (B/s) | Total</p>
<p>Cardiff | 1 | Buy | 1000</p><p>
Cardiff | 1 | Sell | 500</p><p>
Cardiff | 2 | Buy | 100</p><p>
Bristol | 1 | Buy | 200</p><p>
Bristol | 1 | Sell | 100

</p><p></p>
What I need if possible is, when City and Zone match and there is both a Buy and Sell for that pair, then do a calculation. So in the above case I would like to do a calculation only on Cardiff Zone 1 and Bristol Zone 1 (as Cardiff Zone 2 only has one line). The calculation is to aggregate the two, so if there is more sells than buys, I only want the sell line but want to do Total Sell - Total Buy to get a net of the two.