0

I am trying to filter out the data from my excel sheet using Python. When I filter by car "Make" and "Model," it works fine, but when I add a "Year," it does not return any data(Empty). It works with me only if I add any text at the beginning of each cell for the "Year" Column. How can I get the program to filter without adding text to every cell in the "Year" column.

here is function code][1] Empty results since cells sheet do not start with text Return data since cells sheet start with text "A"

1 Answer 1

2

car_year is user input and input are strings in Python. Presumably "Year" is dtype int column, so df['Year']==car_year returns a Series of Falses. To get your desired outcome, convert car_year to int:

car_filter = df[(df['Make']==car_make) & (df['Model']==car_model) & (df['Year']==int(car_year))]
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.