Python Pandas Tutorial (Part 4): Filtering – Using Conditionals to Filter Rows and Columns



In this video, we will be learning how to filter our Pandas dataframes using conditionals.

This video is sponsored by Brilliant. Go to to sign up for free. Be one of the first 200 people to sign up with this link and get 20% off your premium subscription.

In this Python Programming video, we will be learning how to write conditionals in or to filter our data within our Pandas dataframes. This is a fundamental skill to have when using Pandas because it is one of the first things most people do when starting a new Pandas project. Let’s get started…

The code for this video can be found at:

StackOverflow Survey Download Page –

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python #Pandas

Nguồn: https://benjaminjcohen.com/

Xem thêm bài viết khác: https://benjaminjcohen.com/cong-nghe/

39 Comments

  1. Thank you for your videos.

  2. I have referred to three video tutorials/courses before this and this is by far the best course on pandas with complete coverage.
    You deserve a million likes for this series. This course is priceless.

  3. Your in-depth knowledge in python is astonishing!
    The thing that always amazes me is, when you finish explaining a topic and I ask myself " Now what if I try to do that?" kinda questions and within no seconds I see you explaining the same question! 😳
    Do you mind read your viewers or what? 😅
    Anyways, you are a legend <3

  4. best course seriously!!! Quality content.You could have put it on Udemy and earn more but you put it on youtube. Thanks : ).Please do video on Sklearn, Tensorflow.

  5. So far so good explanation..I have been watching the series since its started…I came again to revise.
    just a quick suggestion from my side…please give a suitable name to filter variable so that it will look readable if someone wants to understand whats happening.

  6. @Corey Schafer your content are really awesome. can you please tell me where can i practice all this concepts.

  7. Corey, you're a god of teaching, you don't leave out anything unexplained. Thank you

  8. i like his kinda southern accent lmao

  9. THANKS! finally I get the filtering from pandas.

  10. case:1 filt=(df[' last']=='Doe')
    df.loc[filt ] # It works
    # but when we try this…
    case:2 filt=df[' last ']
    df.loc[' filt ']
    # It doesn't work what's the difference…in both cases

  11. Hey! at 6:30 how to get only email not the index number

  12. Great series. I would recommend going through these tutorials once with the given dataset, and then going through it again using a dataset you're interested in. Dw, it will go alot faster the 2nd time around, and you'll get great practice actually finding insights you care about.

  13. this briliant.org might actually not be a bad idea..

  14. 19:22 let us know when you do a video on strings! Can't wait for that and if you need any suggestions on any of the methods in the pandas …/text.html let us know! Thanks for all your hard work Corey!

  15. There is also someone from Senegal west Africa 🙂
    you are amazing !

  16. Corey, this is simply great! Thanks!

  17. I would be interested in a video about truth tables.

  18. Is there a way to see that truncated text?

  19. There's a little mistake at 9:20. The opposite of this conditional has & instead of |. So:

    filt_2 = (df['last'] == "Schafer") | (df["first"] == "John")

    ~filt_2 = (df['last'] == "Schafer") & (df["first"] == "John")

    Still, great videos. I'm very grateful. Please keep it up.

  20. That is really useful and clearly

  21. You mentioned you may do a separate video on the .str methods Pandas offers and their use. Seems to be a lot of string processing power in .str and it appears to not be covered well (if at all) by others on YouTube. I understand that a lot of the functionality is similar to normal python string processing but Pandas .str appears to have lots more (including direct use of regex expressions) and, of course, vectorized operations. I'd really like to see you do a detailed video on .str, think it would be helpful to many. Thanks.

  22. I would like to ask, if one of my column named "check" has json format like [{id:'1', name:'true'}, {id:'2', name:'false'}] . How should I filter to get all the rows that have the column with value 'false' in its column "check"

  23. I let your ads play all the way thru. Fives minutes in exchange for what you’re giving…light work. Keep it up brotha!

  24. you can call it a 'mask'. 😉

  25. I appreciate the effort which you are putting to create amazing content series. Which is benefiting all of us. Thanks a lot for this.

    I got an error while using:

    df.loc(filt)

    error is :

    —————————————————————————

    TypeError Traceback (most recent call last)

    <ipython-input-34-9219b7517587> in <module>

    —-> 1 df.loc(df['last'] == 'Doe')

    c:userszahoor ahmadappdatalocalprogramspythonpython38-32libsite-packagespandascoreindexing.py in __call__(self, axis)

    576

    577 if axis is not None:

    –> 578 axis = self.obj._get_axis_number(axis)

    579 new_self.axis = axis

    580 return new_self

    c:userszahoor ahmadappdatalocalprogramspythonpython38-32libsite-packagespandascoregeneric.py in _get_axis_number(cls, axis)

    396 @classmethod

    397 def _get_axis_number(cls, axis):

    –> 398 axis = cls._AXIS_ALIASES.get(axis, axis)

    399 if is_integer(axis):

    400 if axis in cls._AXIS_NAMES:

    c:userszahoor ahmadappdatalocalprogramspythonpython38-32libsite-packagespandascoregeneric.py in __hash__(self)

    1796

    1797 def __hash__(self):

    -> 1798 raise TypeError(

    1799 f"{repr(type(self).__name__)} objects are mutable, "

    1800 f"thus they cannot be hashed"

    TypeError: 'Series' objects are mutable, thus they cannot be hashed

  26. Hi Corey, Please create some video lectures on numpy?

  27. Should you have used CompTotal to compare the salaries? Great as usual. Thank you so much for these videos.

  28. Please Corey make video on Python machine learning library too. Thanks for all your effort

  29. Dear Corey, Enjoyed your videos.
    Can we apply two filter, like df.loc[filt1, filt2] assuming comma be treated as &(AND operator)

  30. will you do a video series on tkinter ?

  31. Though we have an idea of the concept, there will always be something new to learn from your videos. As usual thanks a lot.

  32. Corey – thanks for these videos – they are great! Is there a way for the filtering columns and values to be specified by a user (using the input command)?

  33. Hi,

    I tried to run this line :
    df.nlargest(3, 'ConvertedComp')
    i get this error :TypeError: Column 'ConvertedComp' has dtype object, cannot use method 'nlargest' with this dtypeand
    I read that maybe its my Pandas version?
    My versions :
    python: 3.7.1.final.0
    pandas: 0.23.4

    Anybody else that get this error?

  34. I rarely comment but I've watched alot of Pandas tutorials on youtube and this is by far the best one Ive seen. Subscribed.

    Will you be doing a Scikit-learn tutorial in the future?

  35. You're a good man Corey Schafer, thanks for the quality content.

Leave a Reply

Your email address will not be published. Required fields are marked *