Home > Net >  How can I filter by numbers in an excel sheet using Python codes?
How can I filter by numbers in an excel sheet using Python codes?

Time:02-20

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"

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))]
  • Related