I am using the following code to go through a table with serial numbers and months and look for a equivalent service-log in another table to determine for each line, if there was a service in the recent 12 months. The code works but is very slow. Does anyone have a hint for a more performant alternative?
Test_Machines["Loyal"]=Test_Machines.apply(lambda x: ServiceLogs.isin({"serialnumber": [x.serialnumber] ,"request_date" : pd.date_range(x.Year_Month.to_timestamp()-pd.offsets.DateOffset(years=1),x.Year_Month.to_timestamp())}).all(axis=1).any(), axis=1)
Thanks in advance!
Richard