How to filter Pandas DataFrame by values of columns

0 votes

Hi Guys,

I have a Dataframe in Pandas. I want to filter the DataFrame by values of columns. How can I do that?

Oct 20, 2020 in Python by akhtar
• 38,230 points
438 views

1 answer to this question.

0 votes

Hi@akhtar,

You can filter Pandas Dataframe with the loc function. For example, to find the instances in a pandas Dataframe where the values of a column are between some values (‘A’ and ‘B’), you can use:

filtered_df = df.loc[(df['col'] >= A) & (df['col'] <= B)] 
    answered Oct 20, 2020 by MD
    • 95,360 points

    Related Questions In Python

    0 votes
    1 answer

    How to combine two columns of text in pandas dataframe?

    If both columns are strings, you can ...READ MORE

    answered Jan 5, 2021 in Python by Gitika
    • 65,890 points
    1,030 views
    0 votes
    1 answer

    How to print all the index of Pandas Dataframe?

    Try this: print(df.index.values) READ MORE

    answered Apr 8, 2019 in Python by Yogi
    2,728 views
    0 votes
    1 answer

    How to find the sum of rows in Pandas dataframe?

    You can use a combination groupby function with the sum() method. ...READ MORE

    answered May 9, 2019 in Python by Jisha
    3,367 views
    +1 vote
    2 answers

    How to display column names of Pandas Dataframe?

    print(list(your_df)) READ MORE

    answered Jan 18, 2020 in Python by anonymous
    20,946 views
    0 votes
    1 answer
    0 votes
    1 answer

    How to create Pandas series from dictionary?

    Here's a sample script: import pandas as pd import ...READ MORE

    answered Apr 1, 2019 in Python by Prateek
    1,626 views
    0 votes
    1 answer

    Python: Issue with 'unexpected end of pattern'

    I should start by stating that using ...READ MORE

    answered Sep 12, 2018 in Python by Priyaj
    • 58,080 points
    1,409 views
    0 votes
    1 answer

    How to create Pandas series from numpy array?

    Hi. Refer to the below command: import pandas ...READ MORE

    answered Apr 1, 2019 in Python by Pavan
    2,553 views
    +1 vote
    1 answer

    How to change the order of DataFrame columns in pandas?

    Hi@akhtar, You can rearrange a DataFrame object by ...READ MORE

    answered Oct 20, 2020 in Python by MD
    • 95,360 points
    303 views
    +1 vote
    3 answers

    How to change/update cell value in Python Pandas dataframe?

    You can use the at() method to ...READ MORE

    answered Apr 8, 2019 in Python by Kunal
    141,182 views
    webinar REGISTER FOR FREE WEBINAR X
    Send OTP
    REGISTER NOW
    webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP