A data scientist has a Spark DataFrame spark_df. They want to create a new Spark DataFrame that contains only the rows from spark_df where the value in column discount is less than or equal 0.
Which of the following code blocks will accomplish this task?
To filter rows in a Spark DataFrame based on a condition, the filter method is used. In this case, the condition is that the value in the 'discount' column should be less than or equal to 0. The correct syntax uses the filter method along with the col function from pyspark.sql.functions.
Correct code:
from pyspark.sql.functions import col filtered_df = spark_df.filter(col('discount') <= 0)
Option A and D use Pandas syntax, which is not applicable in PySpark. Option B is closer but misses the use of the col function.
In
9 months agoChristoper
9 months agoYaeko
9 months agoTamar
10 months agoGarry
10 months agoDottie
10 months agoCarmen
10 months agoAliza
10 months agoReena
11 months agoDick
11 months agoMing
11 months agoErick
11 months agoRashida
11 months agoThad
11 months agoTijuana
11 months agoSon
11 months agoDarci
11 months agoLouvenia
11 months agoTheron
11 months agoChantell
11 months agoMiesha
2 years agoAnnalee
2 years agoMitsue
2 years agoTegan
2 years agoAlisha
2 years agoTheodora
2 years agoSharen
2 years agoLashon
2 years agoKarl
2 years agoMayra
2 years agoLakeesha
2 years agoWhitley
2 years agoEleonora
2 years agoAlida
2 years agoDalene
2 years agoCherry
2 years agoLorrie
2 years agoAmmie
2 years agoSharen
2 years ago