Answers for "how to check for 2 condition in pandas"

5

how to slicing dataframe using two conditions

# when you wrap conditions in parantheses, you give order
# you do those in brackets first before 'and'
# AND
movies[(movies.duration >= 200) & (movies.genre == 'Drama')]
Posted by: Guest on March-21-2020
6

or condition in pandas

df1 = df[(df.a != -1) & (df.b != -1)]
Posted by: Guest on June-03-2020
2

pandas select rows by multiple conditions

>>> df["A"][(df["B"] > 50) & (df["C"] == 900)]
2    5
3    8
Name: A, dtype: int64
    
>>> df.loc[(df["B"] > 50) & (df["C"] == 900), "A"]
2    5
3    8
Name: A, dtype: int64
>>> df.loc[(df["B"] > 50) & (df["C"] == 900), "A"].values
array([5, 8], dtype=int64)
>>> df.loc[(df["B"] > 50) & (df["C"] == 900), "A"] *= 1000
>>> df
      A   B    C
0     9  40  300
1     9  70  700
2  5000  70  900
3  8000  80  900
4     7  50  900
Posted by: Guest on March-30-2020

Code answers related to "how to check for 2 condition in pandas"

Python Answers by Framework

Browse Popular Code Answers by Language