Distinct Rows and Distinct Count from Spark Dataframe

In this blog, we will learn how to get distinct values from columns or rows in the Spark dataframe. We will also learn how we can count distinct values. We will be using our same flight data for example.

Distinct Values from Dataframe

Consider that we want to get all combinations of source and destination countries from our data. We can easily do this using the following code.

In spark, we can chain multiple operations one after another. Here we are using where clause with distinct values.

Counting Distinct Values

We can also easily count distinct values by chaining count function after we distinct function.

Using dropDuplicates function

If we want to drop all duplicate rows from the dataframe we can also use “dropDuplicates” function.

I hope this helps. See you soon 🙂

Distinct Rows and Distinct Count from Spark Dataframe

Mahesh Mogal

I am passionate about Cloud, Data Analytics, Machine Learning, and Artificial Intelligence. I like to learn and try out new things. I have started blogging about my experience while learning these exciting technologies.

Let us connect

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Copy link
Powered by Social Snap