1

Im trying to filter the data frame (stops_trips_vehicles) based on user input - specifying hour (departure_time column) and the stop name(stop_name column). Each time I am getting wrong value as a result, even if the input data is matching in the data frame.

hour = input('Input hour ') 
stop = input('Input stop name ')

results = [] 
for index, row in stops_trips_vehicles.iterrows():
    if row['stop_name'] == stop and row['departure_time'] == hour:
        results.append(row)
        print(results)
    else:
        print('wrong value')
        break
0

1 Answer 1

1

You don't need to filter the DataFrame row by row:

hour = input('Input hour ') 
stop = input('Input stop name ')

results = stops_trips_vehicles[(stops_trips_vehicles['stop_name']==stop) & (stops_trips_vehicles['departure_time']==hour)]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.