Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

select rows with multiple conditions pandas query

df.loc[(df['Salary_in_1000']>=100) & (df['Age']< 60) & (df['FT_Team'].str.startswith('S')),['Name','FT_Team']]
Comment

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
Comment

select rows with multiple conditions pandas query

df.query('Salary_in_1000 >= 100 & Age < 60 & FT_Team.str.startswith("S").values')
Comment

select rows with multiple conditions pandas query

df.loc[idx]
Comment

get df based on multiple conditions in column

user_df[user_df['colA'].isnull() & user_df['colB'] > 0]
Comment

PREVIOUS NEXT
Code Example
Python :: np arange 
Python :: python asctime 
Python :: python set remove multiple elements 
Python :: pandas dataframe get number of occurrence in column 
Python :: import get_object_or_404 
Python :: schedule computer shutdown python 
Python :: print list in python 
Python :: numpy check if an array is all zero 
Python :: python for loop one line 
Python :: replace nan numpy array 
Python :: python stop while loop after time 
Python :: python remove suffix 
Python :: change tkinter app icon 
Python :: plot a circle in python using equation of a circle 
Python :: how to close a python program 
Python :: number system conversion python 
Python :: Find the title of a page in python 
Python :: string to list python 
Python :: python nonlocal 
Python :: fork function in python 
Python :: python custom sort 
Python :: python insert to sorted list 
Python :: python how to make multiple box plots 
Python :: sum group by pandas and create new column 
Python :: convert timedelta to int 
Python :: python list of dictionaries to excel 
Python :: how to run a python script 
Python :: pass keyword python 
Python :: find sum of factors of a number python 
Python :: matplotlib vertical line 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =