I have two DataFrames, I need to merge both, and I need to add a column that specifies if it is accepted or not.
I have this:
dfa[dfa.CONTROL.isin([334030860978638])]
Out[107]:
CONTROL A B DATE_HOUR
1629136 334030860978638 525562414612 52447860015000 2015-08-02 16:32:00
1629137 334030860978638 525562414612 52447860015000 2015-08-02 16:42:32
1629138 334030860978638 525562414612 52447860015000 2015-08-02 18:33:12
1629139 334030860978638 525562414612 52447860015000 2015-08-03 19:40:19
dfb[dfb.control.isin([334030860978638])]
Out[108]:
control a b date_hour
id
299366338 334030860978638 525562414612 447860015000 2015-08-02 16:33:08
299392621 334030860978638 525562414612 447860015000 2015-08-02 16:43:40
299665465 334030860978638 525562414612 447860015000 2015-08-02 18:34:21
view = dfa.merge(dfb, left_on=['CONTROL', 'A', 'B'],
right_on=['control', 'a', 'b'], how='outer')
I need to compare DATE_HOUR, with date_hour and if records are in time range for example 3600 seconds, also I need to determine if multiple records exist in time then I'll get the nearest one and to mark it, in a new column accepted I'll set as True, otherwise False.
my expected output:
CONTROL A B DATE_HOUR control a b date_hour accepted
334030860978638 525562414612 52447860015000 2015-08-02 16:32:00 334030860978638 525562414612 52447860015000 2015-08-02 16:32:08 True
334030860978638 525562414612 52447860015000 2015-08-02 16:42:32 334030860978638 525562414612 52447860015000 2015-08-02 16:43:40 True
334030860978638 525562414612 52447860015000 2015-08-02 18:33:12 334030860978638 525562414612 52447860015000 2015-08-02 18:34:21 True
334030860978638 525562414612 52447860015000 2015-08-03 19:40:19 NaN NaN Nan NaT False
Can I use the apply method to this task?, can someone help me to do in the right way using pandas.