I have two data frames,
import pandas as pd
a = pd.DataFrame( { 'port':[1,1,0,1,0], 'cd':[1,2,3,2,1], 'date':["2014-02-26","2014-02-25","2014-02-26","2014-02-26","2014-02-25"] } )
b = pd.DataFrame( { 'port':[0,1,0,1,0], 'fac':[2,1,2,2,3], 'date': ["2014-02-25","2014-02-25","2014-02-26","2014-02-26","2014-02-27"] } )
What I need to do is take every date-port pair, like say port 0 and date 2014-02-25, look up the fac value in b and fill this into a new column in a. The output should therefore look like
port cd date fac
1 1 "2014-02-26" 2
1 2 "2014-02-25" 1
... (so on) ...
I tried just merging the frames on both date and port but got an error, which I think is due to the fact that the data frames are of different sizes--and I kind of don't expect that it would work anyway.