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,240 points
325 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,340 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,850 points
    842 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,264 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,174 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,734 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,551 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,060 points
    1,151 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,378 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,340 points
    259 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
    138,073 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