I have a problem:
import pandas
new_dict={
'a':1,
'b':2,
'else':4
}
df=pandas.DataFrame([['new1','a'],['new2','b'],['new3','c'],['new4','d'],['new5','b']],columns=['new','id'])
df like this
new id
0 new1 a
1 new2 b
2 new3 c
3 new4 d
4 new5 b
the result I wanted:
new id
0 new1 1
1 new2 2
2 new3 4
3 new4 4
4 new5 2
I am trying to convert a dict to a data framework and use the merge method. but "else" does not match:
import pandas
new_dict={'newid':['a','b','else'],
'idd':[1,2,4]}
df2=pandas.DataFrame(new_dict,columns=['newid','idd'])
df=pandas.DataFrame([['new1','a'],['new2','b'],['new3','c'],['new4','d'],['new5','b']],columns=['new','id'])
I am trying to use the pandas merge method to solve this problem, but I do not know what the next step should be. Thank!