Below is a small sample of my dataframe.
In [10]: dfOut[10]:TXN_KEY Send_Agent Pay_Agent Send_Amount Pay_Amount
0 13272184 AWD120279 AEU002152 85.99 85.04
1 13272947 ARA030122 AEV000034 402.01 400.00
2 13273453 API185805 API190139 22.98 22.98
3 13273870 ANO080012 API352676 490.00 475.68
4 13274676 AUK359401 AED002782 616.16 600.87
5 13274871 ACL000105 ACB020203 193.78 185.21
6 13275194 ADA374245 ANP023424 100.00 98.50grouped = df.groupby('Send_Agent')
A function to calculate the number of times the Send_Amount is same as the next one works just fine.
def repeat_count(s):return (s.shift() == s).sum()In [35]: result = grouped.agg({'Send_Amount':[repeat_count]})In [36]: resultOut[36]:Send_Amountrepeat_count
Send_Agent
A03010016 0
A03020026 0
A10000075 0
A10000316 0
A10000932 0
A10060013 0
A10080022 0
A11120030 0
But when I am trying to calculate the count of all the Send_Agent where Send_Amount is between 900 and 1000 and I am getting an error:
In [27]: def banded_txns(s):
return(s >=900.00 & s < 1000.00).count()In [28]: result = grouped.agg({'Send_Amount':banded_txns})TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
I am not able to figure out why it is working for one type of comparison and not for the other. Thanks in advance.