I have a dataset which resembles something like this:
ID AMT TAG
1 100 A
2 120 B
1 25 B
1 110 A
I have to calculate the standard deviation of each tag for each ID,something like this:
ID A_STD B_STD
1 5 0
2 0 0
I am trying something like this:
out=df[df['TAG']=='A']
out=out.groupby('ACCT_NB').agg(
A_STD=('TXN_AMT',lambda x:np.std(x))
)
For each TAG I am doing this. Is there a way to possibly minimise this code?