How to Build an End-To-End ML Pipeline With Databricks & Aporia
This tutorial will show you how to build a robust end-to-end ML pipeline with Databricks and Aporia. Here’s what you’ll...
🤜🤛 Aporia partners with Google Cloud to bring reliability and security to AI Agents - Read more
A row in a DataFrame can be considered as an observation with several features that are represented by columns. We sometimes need to remove observations whose feature values do not fit the given condition. In this how-to article, we will learn how to delete rows based on column values in Pandas and PySpark DataFrames.
We usually have multiple ways of writing the desired or undesired condition.
# not equals
df = df[df["Item"] != "Broccoli"]
# tilde (not) operator
df = df[~(df["Item"] == "Broccoli")]
The tilde operator is especially useful when the undesired condition consists of multiple values. Let’s say we have a larger DataFrame and want to delete rows with Broccoli, Potato, and Cucumber. Here are different ways of doing this operation:
# not equals and & operator
df = df[
(df["Item"] != "Broccoli") &
(df["Item"] != "Cucumber") &
(df["Item"] != "Potato")
]
# tilde (not) operator and isin method
df[~(df["Item"].isin(["Broccoli","Cucumber","Potato"]))]
# isin method and False
df = df[df["Item"].isin(["Broccoli","Cucumber","Potato"]) == False]
As we see in the third method above, the False condition can be used instead of the tilde operator.
We can use the filter or where function. The syntax is quite similar to the syntax of Pandas.
# filter function
df = df.filter(df["Item"] != "Broccoli")
# where function
df = df.where(df["Item"] != "Broccoli")
With multiple undesired conditions, we can use the isin method with tilde operator or False condition.
# isin and tilde
df = df.filter(~df["Item"].isin(["Broccoli","Cucumber","Potato"]))
# isin and False
df = df.filter(df["Item"].isin(["Broccoli","Cucumber","Potato"]) == False)
This tutorial will show you how to build a robust end-to-end ML pipeline with Databricks and Aporia. Here’s what you’ll...
Dictionary is a built-in data structure of Python, which consists of key-value pairs. In this short how-to article, we will...
DataFrame is a two-dimensional data structure with labeled rows and columns. Row labels are also known as the index of...
DataFrames are great for data cleaning, analysis, and visualization. However, they cannot be used in storing or transferring data. Once...
In this short how-to article, we will learn how to sort the rows of a DataFrame by the value in...
In a column with categorical or distinct values, it is important to know the number of occurrences of each value....
NaN values are also called missing values and simply indicate the data we do not have. We do not like...
DataFrame is a two-dimensional data structure, which consists of labeled rows and columns. Each row can be considered as a...