I have 2 CSV files, as below.
- I want a new column
Difference
, where...- if a mobile number appears within the date range of
Book_date
...App_date
:Difference
= differenceApp_date
andOccur_date
- or NaN if it doesn't occur in that date range.
- if a mobile number appears within the date range of
- I also want to filter it based on a unique category and mobile_number
csv_1
Mobile_Number Book_Date App_Date
503477334 2018-10-12 2018-10-18
506002884 2018-10-12 2018-10-19
501022162 2018-10-12 2018-10-16
503487338 2018-10-13 2018-10-13
506012887 2018-10-13 2018-10-21
503427339 2018-10-14 2018-10-17
csv_2
Mobile_Number Occur_Date
503477334 2018-10-16
506002884 2018-10-21
501022162 2018-10-15
503487338 2018-10-13
501428449 2018-10-18
506012887 2018-10-14
I want a new column in csv_1, where if a mobile number appears within the date range of Book_date and App_date in csv_2, the difference between App_date and the Occur_date or NaN if it doesn't occur in that date range. The output should be
Output
Mobile_Number Book_Date App_Date Difference
503477334 2018-10-12 2018-10-18 2
506002884 2018-10-12 2018-10-19 -2
501022162 2018-10-12 2018-10-16 1
503487338 2018-10-13 2018-10-13 0
506012887 2018-10-13 2018-10-21 7
503427339 2018-10-14 2018-10-17 NaN
EDIT:
If I want to filter it based on a unique category and mobile_number on the above two csv files. How to do the same?
csv_1
Category Mobile_Number Book_Date App_Date
A 503477334 2018-10-12 2018-10-18
B 503477334 2018-10-07 2018-10-16
C 501022162 2018-10-12 2018-10-16
A 503487338 2018-10-13 2018-10-13
C 506012887 2018-10-13 2018-10-21
E 503427339 2018-10-14 2018-10-17
csv_2
Category Mobile_Number Occur_Date
A 503477334 2018-10-16
B 503477334 2018-10-13
A 501022162 2018-10-15
A 503487338 2018-10-13
F 501428449 2018-10-18
C 506012887 2018-10-14
I want the output to be filtered based on the Mobile_Number and the Category
Output
Category Mobile_Number Book_Date App_Date Difference
A 503477334 2018-10-12 2018-10-18 2
B 503477334 2018-10-07 2018-10-16 3
C 501022162 2018-10-12 2018-10-16 NaN
A 503487338 2018-10-13 2018-10-13 0
C 506012887 2018-10-13 2018-10-21 7
E 503427339 2018-10-14 2018-10-17 NaN