2021年4月28日星期三

Compare multiple columns of two data frames using pandas

I have two data frames; df1 has Id and sendDate and df2 has Id and actDate. The two df's are not the same shape - df2 is a lookup table. There may be multiple instances of Id.

ex.

df1 = pd.DataFrame({"Id": [1, 1, 2, 3, 2],                       "sendDate": ["2019-09-24", "2020-09-11", "2018-01-06", "2018-01-06", "2019-09-24"]})    df2 = pd.DataFrame({"Id": [1, 2, 2],                       "actDate": ["2019-09-24", "2019-09-24", "2020-09-11"]})  

I want to add a boolean True/False in df1 to find when df1.Id == df2.Id and df1.sendDate == df2.actDate.

I'm new to python from R, so please let me know what other info you may need.

https://stackoverflow.com/questions/67309721/compare-multiple-columns-of-two-data-frames-using-pandas April 29, 2021 at 09:00AM

没有评论:

发表评论