Say I have the pandas DataFrame below:
A B C D
0 foo one 2 0
1 foo two 2 0
2 foo three 2 0
4 bar one 2 1
5 bar two 2 1
6 bar three 2 1
I want to append a column 'E' with value (aaa,bbb,ccc)according to the value of B and repeat itself for different 'A'
aaa=0.03
bbb=0.2
ccc=0.14
Expected output:
A B C D E
0 foo one 2 0 0.03
1 foo two 2 0 0.2
2 foo three 2 0 0.14
4 bar one 2 1 0.03
5 bar two 2 1 0.2
6 bar three 2 1 0.14
I only know how to do this if I use groupby()
to get the value of E, but how can I do this with constant numbers?