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,210 points
219 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,300 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 in Python by Gitika
    • 65,950 points
    607 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
    1,632 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
    2,925 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,161 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,319 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,140 points
    950 views
    0 votes
    1 answer

    Python: Issue with 'unexpected end of pattern'

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

    answered Sep 24, 2018 in Python by Priyaj
    • 58,140 points
    845 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,300 points
    211 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
    129,546 views