In a Fabric notebook, after loading the Product table into a DataFrame with spark.sql('SELECT * FROM Product'), which PySpark command will display the top 100 rows?

Prepare for the DP-600 Fabric Analytics Engineer Exam. Study with flashcards and multiple choice questions, each offering hints and detailed explanations. Enhance your chances of success on the exam!

Multiple Choice

In a Fabric notebook, after loading the Product table into a DataFrame with spark.sql('SELECT * FROM Product'), which PySpark command will display the top 100 rows?

Explanation:
To show a specific number of rows from a DataFrame in a Fabric notebook, you typically use limit to cap the number of rows and then feed that limited DataFrame to display. The expression display(df.limit(100)) creates a new DataFrame containing at most 100 rows and hands it to the notebook’s render mechanism, which shows them nicely in the cell output. This is the right pattern because display expects a DataFrame to render, not a side-effect call. Using a different approach won’t work as intended: limiting to fewer rows (for example, 50) would show fewer rows; calling show on the DataFrame returns None and prints to the console rather than using the notebook's display rendering; and running a SQL query and then show would also print to the console and isn’t integrated through the notebook’s display function.

To show a specific number of rows from a DataFrame in a Fabric notebook, you typically use limit to cap the number of rows and then feed that limited DataFrame to display. The expression display(df.limit(100)) creates a new DataFrame containing at most 100 rows and hands it to the notebook’s render mechanism, which shows them nicely in the cell output. This is the right pattern because display expects a DataFrame to render, not a side-effect call.

Using a different approach won’t work as intended: limiting to fewer rows (for example, 50) would show fewer rows; calling show on the DataFrame returns None and prints to the console rather than using the notebook's display rendering; and running a SQL query and then show would also print to the console and isn’t integrated through the notebook’s display function.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy