I'm trying to replicate the following SQL code using Pandas functions. This SQL code block contains a groupby and summation of columns based on different conditions.
I tried using pandas groupby and apply functions but couldn't crack the logic.
select id, lcode,
sum(case when type='A' and code='$' AND sub_code='B' then
amount else 0 end) as A_amount,
sum(case when type='P' and code='$' AND sub_code='B' then
amount else 0 end) as P_amount,
sum(case when type='W' and code='$' AND sub_code='B' then
amount else 0 end) as W_amount
from TRANSACTIONS
where id in ('1235','2456','4231','2341','9624')
GROUP BY id, lcode
The requirement is to replicate this logic in Python using Pandas functions.