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.
CodePudding user response:
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))]