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,260 points
1,076 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,460 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,770 points
    1,954 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
    5,395 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
    4,608 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
    22,243 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
    2,318 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,020 points
    2,629 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
    3,506 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,460 points
    860 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
    147,371 views
    webinar REGISTER FOR FREE WEBINAR X
    REGISTER NOW
    webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP