How do I apply multiple filter criteria to a pandas DataFrame?




[ad_1]

Let’s say that you want to filter the rows of a DataFrame by multiple conditions. In this video, I’ll demonstrate how to do this using two different logical operators. I’ll also explain the special rules in pandas for combining filter criteria, and end with a trick for simplifying chained conditions!

SUBSCRIBE to learn data science with Python:
https://www.youtube.com/dataschool?sub_confirmation=1

JOIN the “Data School Insiders” community and receive exclusive rewards:
https://www.patreon.com/dataschool

== RESOURCES ==
GitHub repository for the series: https://github.com/justmarkham/pandas-videos
“isin” documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html

== LET’S CONNECT! ==
Newsletter: https://www.dataschool.io/subscribe/
Twitter: https://twitter.com/justmarkham
Facebook: https://www.facebook.com/DataScienceSchool/
LinkedIn: https://www.linkedin.com/in/justmarkham/

Source


[ad_2]

Comment List

  • Data School
    December 8, 2020

    Thank you for helping me. You just saved my project !!

  • Data School
    December 8, 2020

    You Are the Best Data Science Teacher……….Thanks for Sharing

  • Data School
    December 8, 2020

    Very clear explanations. Thank you!

  • Data School
    December 8, 2020

    Excellent video, very well explained. One question. Isin is for exact match only? using you example if some row has "Crime." instead of "Crime" still consider that row? there is another method to incluid that variation on the write? thank you.

  • Data School
    December 8, 2020

    hii can u fetch out a movie with highest rating and lowest duration pls answer fast please

  • Data School
    December 8, 2020

    You are the best!

  • Data School
    December 8, 2020

    Simply the best, so easy to understand to follow and to learn. Thank you.

    I have a question, what if I want to know which genres are associated to an actor?

    I mean, how can I split that column?

  • Data School
    December 8, 2020

    Nice explanation!

  • Data School
    December 8, 2020

    I really appreciate your time and effort in these amazing videos. I learned too much

  • Data School
    December 8, 2020

    how do I display the unique values in the dataframe column and inplace them?

  • Data School
    December 8, 2020

    based.

  • Data School
    December 8, 2020

    I know this might be a bit too late, but a good way to explain the booleans might be with a Vern's Diagram. It is explicit and really easy to represent.
    Nevertheless, amazing work and this has been helping me a lot more than anything I have from my teacher.

  • Data School
    December 8, 2020

    Hi ,
    How to select particular column using mutiple filter criteria
    like movies[(movies["duration"]>=200) & (movies["genre"].isin(["Drama","Action"]))].title
    here i can get only title where these conditions are met but if i want to get title and star_rating then how to do that?

  • Data School
    December 8, 2020

    Hi, how to apply multiple filter in loc rows ? ie: i tried movies.loc[[movies.dutation>=200],[movies.genre=='Drama'],['duration',['genre']] but it dint work , i can able to apply only one filter in rows like movies.loc[movies.duration>=200, [ 'duration','genre']]

  • Data School
    December 8, 2020

    I get alot from your videos. Stay blessed

  • Data School
    December 8, 2020

    May I have your Wats app number please .

  • Data School
    December 8, 2020

    How can we filter the data by each column . ?

  • Data School
    December 8, 2020

    I have a question ?

  • Data School
    December 8, 2020

    and God directed me to your page. Thanks

  • Data School
    December 8, 2020

    4:10 it's exactly what I was trying to do hahah

  • Data School
    December 8, 2020

    Helped me.

  • Data School
    December 8, 2020

    Thanks for your valuable lesson. May I know which screen video recorder software do you use because clarity is great. Thanks

  • Data School
    December 8, 2020

    What if you were to filter the title that has for example "Fight" on the title. How to do it?

  • Data School
    December 8, 2020

    You're a fantastic teacher. Well done & thank you!

  • Data School
    December 8, 2020

    I want to filter 2 or more categories data in a single column so would I do that?

  • Data School
    December 8, 2020

    Can i plot on filter data if yes yes. Please make video on that

  • Data School
    December 8, 2020

    I am very impressed of how you exxplain the functions in pandas. It works very fine for me. And +350 others I guess.

  • Data School
    December 8, 2020

    Someone, somewhere around the globe, (and by that I mean some random Indian guy,) kills himself everytime someone subscribes to this channel.

  • Data School
    December 8, 2020

    Thank you for great videos!

  • Data School
    December 8, 2020

    HiI!
    Could you please specify that how can we know that when to use " ( ) " or " [ ] " while running any function or method?

  • Data School
    December 8, 2020

    Why is this man looking at me through his nose?

  • Data School
    December 8, 2020

    how to get multiple columns with single condition

    on imdb_ratings dataset
    suppose i want column [ ''title", "genre"] that have star_rating < 9

Write a comment