
Answer-first summary for fast verification
Answer: storesDF.first().sqft
The correct answer is E. Here's the analysis: - **Option A**: Using `col("sqft")` to index a Row is invalid. Rows require column names as strings, not Column objects. - **Option B**: DataFrame does not support `[0]` index-based access. - **Option C**: `collect(l)` contains a typo (likely `collect()[0]`), but even if corrected, `collect()` retrieves all rows, which is inefficient for extracting a single row. - **Option D**: `first` is a method and requires parentheses (`first()`) to invoke. Missing parentheses makes this syntax incorrect. - **Option E**: Correctly uses `first()` to get the first Row and accesses the `sqft` column via dot notation, which is valid in PySpark for Row objects.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Which of the following code blocks retrieves the value of the column sqft from the first row of the DataFrame storesDF?
A
storesDF.first()[col("sqft")]
B
storesDF[0]["sqft"]
C
storesDF.collect(l)[0]["sqft"]
D
storesDF.first.sqft
E
storesDF.first().sqft
No comments yet.