i need the help of the community to solve an issue. Basically i have a excel database with a series of information: train number, departure date, fare, owner of the train (NTV or TRN) and the market (which station the train is going to cover).
Now, i have created a code that filter some of those information but i miss a piece: how can I, given a specific market, class and range of departure dates, find FOR EACH TRAIN WITH CXR = "NTV" a train that has a CXR = "TRN" AND has a departure date that falls within plus or minus 40min from the NTV train (i would need to display those information and also the fare)?
I would also need to display the result side by side (preferably also exporting on excel) for a quick and easy comparison. Following, the code.
import pandas as pd
import datetime
data = pd.read_excel (r'C:\Users\robda\Downloads\out_ow_train.xlsx')
pd.DataFrame([['2020-03-05 00:00:00', 8502, 'B',71,'FCOFLR','TRN']],
columns = ['DDTIME2','DTRAIN','CLASS','FARE','MARKET','CXR'])
OUTPUT
DDTIME2 DTRAIN CLASS FARE MARKET CXR
2020-03-05 00:00:00 8502 B 71 FCOFLR TRN
NS = ['TRNMXP','TRNPMF','TRNBLQ','TRNFLR','TRNFCO','TRNNAP','TRNQSR','MXPPMF','MXPBLQ','MXPFLR','MXPFCO','MXPNAP','MXPQSR',
'PMFBLQ','PMFFLR','PMFFCO','PMFNAP','PMFQSR','BLQFLR','BLQFCO','BLQNAP','BLQQSR','FLRFCO',
'FLRNAP','FLRQSR','FCONAP','FCOQSR','NAPQSR']
dates = ["2020-03-05","2020-03-10"]
classes = ['E']
time = pd.date_range( start = min(dates), end = max(dates), freq='Min')
df.MARKET.isin(NS)
df.DDATE.isin(dates)
df.CLASS.isin(classes)
df.DTIME2.isin(time)
df[df.MARKET.isin(NS) & df.DDATE.isin(dates) & df.CLASS.isin(classes) & df.DTIME2.isin(time)]
P.S. sorry for low quality pic, i have no idea how to update the excel file