I have a dataframe, df, where, whenever a certain string is present, I would like a specific value to be appended to this.
df
id test
aa 5
aa 4
bb 3
cc 2
dd 1
aa 0
Desired
type id test
1000 aa 5
1000 aa 4
500 bb 3
1200 cc 2
200 dd 1
1000 aa 0
I would like to append 1000 to aa
500 to bb, 1200 to cc, and 200 to dd
Doing
I believe I have to create a dictionary key match pairing with this particular post. I am not sure how to keep the other remaining columns as well in the output. Any suggestion is appreciated.
test= {'aa' : 1000, 'bb' : 500, 'cc' : 1200, 'dd' : 200}