Which of the following code blocks returns a DataFrame containing only the rows from DataFrame storesDF where the value in column sqft is less than or equal to 25,000 OR the value in column customerSatisfaction is greater than or equal to 30?
A.
storesDF.filter(col("sqft") <= 25000 | col("customerSatisfaction") >= 30)
B.
storesDF.filter(col("sqft") <= 25000 or col("customerSatisfaction") >= 30)
C.
storesDF.filter(sqft <= 25000 or customerSatisfaction >= 30)
D.
storesDF.filter(col(sqft) <= 25000 | col(customerSatisfaction) >= 30)
E.
storesDF.filter((col("sqft") <= 25000) | (col("customerSatisfaction") >= 30))
Option E, storesDF.filter((col("sqft") <= 25000) | (col("customerSatisfaction") >= 30)), is the correct option. It uses the filter() operation with the conditions (col("sqft") <= 25000) | (col("customerSatisfaction") >= 30) to filter the rows where the value in column sqft is less than or equal to 25,000 OR the value in column customerSatisfaction is greater than or equal to 30.
The correct code block to return a DataFrame containing only the rows from DataFrame storesDF where the value in column sqft is less than or equal to 25,000 OR the value in column customerSatisfaction is greater than or equal to 30 is:
storesDF.filter((col("sqft") <= 25000) | (col("customerSatisfaction") >= 30))
Option A uses a single pipe (|) instead of the correct syntax of two vertical bars (||) to represent "OR" logic, and also uses the wrong syntax for column referencing.
Option B uses the correct or operator, but also uses the wrong syntax for column referencing.
Option C uses the correct operator and syntax for column referencing, but does not use the col() function to reference column names.
Option D uses the col() function, but also uses the wrong syntax for column referencing.
Option E uses the correct syntax for both column referencing and logical operator, and correctly specifies the parentheses to ensure the proper order of operations.
Therefore, the correct answer is E.
storesDF.filter((col("sqft") <= 25000) | (col("customerSatisfaction") >= 30))
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
jds0
4 months agoTmData
1 year, 5 months agoSonicBoom10C9
1 year, 6 months agopierre_grns
1 year, 7 months agopierre_grns
1 year, 7 months agosly75
1 year, 6 months agoevertonllins
1 year, 3 months ago4be8126
1 year, 7 months ago