Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

filter rows pandas

newdf = df[(df.origin == "JFK") & (df.carrier == "B6")]
Comment

filter rows dataframe pandas

# filter Rows Based on condition
df[df["Courses"] == 'Spark'] 
df.loc[df['Courses'] == value]
df.query("Courses == 'Spark'")
df.loc[df['Courses'] != 'Spark']
df.loc[df['Courses'].isin(values)]
df.loc[~df['Courses'].isin(values)]

# filter Multiple Conditions using Multiple Columns
df.loc[(df['Discount'] >= 1000) & (df['Discount'] <= 2000)]
df.loc[(df['Discount'] >= 1200) & (df['Fee'] >= 23000 )]

# Using lambda function
df.apply(lambda row: row[df['Courses'].isin(['Spark','PySpark'])])

# filter columns that have no None & nana values
df.dropna()

# Other examples
df[df['Courses'].str.contains("Spark")]
df[df['Courses'].str.lower().str.contains("spark")]
df[df['Courses'].str.startswith("P")]
Comment

PREVIOUS NEXT
Code Example
Python :: python system of nonlinear equations 
Python :: plot tf model 
Python :: update python in cmd 
Python :: opencv get contours 
Python :: discord.py on command error 
Python :: python sum attribute in list 
Python :: python find which os 
Python :: how to get the location of the cursor screen in python 
Python :: flask marshmallow 
Python :: [Solved] TypeError: can’t multiply sequence by non-int of type str 
Python :: df to np array 
Python :: python number with comma to float 
Python :: ordered char list 
Python :: drop columnd python 
Python :: python project ideas 
Python :: how to clear command prompt python 
Python :: pyspark min column 
Python :: python os exists 
Python :: python every other goes to a list 
Python :: migrate using other database django 
Python :: file to lowercase python 
Python :: python matplotlib hist set axis range 
Python :: make beep python 
Python :: python print dict new line 
Python :: how to find how many processors you have with python 
Python :: extend stack python 
Python :: ModuleNotFoundError: No module named ‘click’ 
Python :: pandas to dict by row 
Python :: sqlalchemy datetime default now create table 
Python :: write list of dicts to csv python 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =