I have a dataset of trader transactions where the variable of interest is Buy/Sell
which is binary and takes on the value of 1 f the transaction was a buy and 0 if it is a sell. An example looks as follows:
Trader Buy/Sell
A 1
A 0
B 1
B 1
B 0
C 1
C 0
C 0
I would like to calculate the net Buy/Sell
for each trader such that if the trader had more than 50% of trades as a buy, he would have a Buy/Sell
of 1, if he had less than 50% buy then he would have a Buy/Sell
of 0 and if it were exactly 50% he would have NA (and would be disregarded in future calculations).
So for trader A, the buy proportion is (number of buys)/(total number of trader) = 1/2 = 0.5 which gives NA.
For trader B it is 2/3 = 0.67 which gives a 1
For trader C it is 1/3 = 0.33 which gives a 0
The table should look like this:
Trader Buy/Sell
A NA
B 1
C 0
Ultimately i want to compute the total aggregated number of buys, which in this case is 1, and the aggregated total number of trades (disregarding NAs) which in this case is 2. I am not interested in the second table, I am just interested in the aggregated number of buys and the aggregated total number (count) of Buy/Sell
.
How can I do this in Pandas?