Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to select specific rows using conditions in pandas?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

We can look at some examples on pandas filtering and see that we can combine multiple filters using & and then we have 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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading