How to select specific rows using conditions in pandas?

Question:

I want to filter my data to only Honda CRVs. I noticed that there are a couple types of Honda CRVs and I can’t find the condition to select CRVs only.

enter image description here

Kinda having a hard time here. Don’t know what to do

Answers:

We can look at some examples on pandas filtering and see that we can combine multiple filters using & and then we can look at some string methods we can use with pandas to see that we have a str.startswith. So we if we combine them into something like this, could work:

honda_crv_df = df_train_new[(df_train_new['Manufacture'] == "Honda") & (df_train_new['Name'].str.startswith('Honda CR-V'))].sort_values(by="Price", ascending=False)

Answered By: Ietu
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.