I have python dict like this:
keysdict={'date': {20: '201012', 21: '201101', 22: '201102', 23: '201103', 24: '201104', 25: '201105', 26: '201106', 27: '201107', 28: '201108', 29: '201109', 30: '201110', 31: '201111'}}
And I have pandas dataframe like this
A B
20 0.123
21 2.123
22 4.45
23 3.2
24 3.1
25 3.9
26 4.2
Now I want to add an extra column C which takes the respective value from dict keys that are in Column A . Like below one
A B C
20 0.123 201012
21 2.123 201101
22 4.45 201102
23 3.2 201103
24 3.1 201104
25 3.9 201105
26 4.2 201106
I tried this
df.loc[:,'C']=keysdict['date'][df.loc['A']]
But getting below error
KeyError: 'the label [A] is not in the [index]