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 :: install python macos catalina 
Python :: from pandas to dictionary 
Python :: check word in list 
Python :: align a text python 
Python :: enumerate in django templte 
Python :: print output 
Python :: list of lists to table python 
Python :: while true loop python 
Python :: pandas filter column with or 
Python :: Get more than one longest word in a list python 
Python :: python qr decomposition 
Python :: create_polygon tkinter 
Python :: python only decimal part 
Python :: AI chatbot in Python - NAYCode.com 
Python :: raise exception without traceback python 
Python :: pandas aggregate dataframe 
Python :: newline in python gives an extra one 
Python :: how to scrape data from a html page saved locally 
Python :: python delete list elements 
Python :: choose value none in pandas 
Python :: how to import nltk 
Python :: faker, generates fake data for you 
Python :: python split at index 
Python :: recursive binary search python 
Python :: how to extract zip file using python 
Python :: python counter 
Python :: how to sort dictionary in ascending order by sorted lambda function in python 
Python :: To Divide or Not To Divide 
Python :: plotly subplots 
Python :: for loop 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =