dimanche 5 avril 2020

Python - Check if multiple values in dataframe A exist in dataframe B

So I am fairly new to python, but am hoping it can help to automate a process that I currently run manually. I just do not know how to approach the below problem, so am hoping to get some help with it if possible, please.

I have two pandas dataframes:

Dataframe A looks like:

| Customer_ID | Booking_date | Dep_Airport | Arvl_Airport | Airline | Departure_date | Class   |
|-------------|--------------|-------------|--------------|---------|----------------|---------|
| XX          | 2020-02-01   | LAX         | LHR          | BA      | 2020-12-01     | First   |
| XX2         | 2020-02-04   | SIN         | SCL          | CX      | 2020-11-05     | Economy |

While dataframe b looks like

| Dep_Airport | Arvl_Airport | Airline | Departure_date |Class    |
|-------------|--------------|---------|----------------|---------|
| LAX         | LHR          | BA      | 2020-12-01     |First    |
| SIN         | SCL          | CX      | 2020-11-05     |Business |

I need to be able to write a function/conditional statement in python (if possible) that somehow does something like so at a customer level:

if dep_airport (A) IN dep_airport (B) AND

   arvl_airport (A) IN arvl_airport (B) AND

   class(A) IN class(B) AND

   departure_date (A) between X and Y 

then 1 else 0 

Note: The data in dataframe b changes weekly.

Any thoughts/ideas or alternatives would be greatly appreciated. Thanks.

Aucun commentaire:

Enregistrer un commentaire