Github Copilot · Free Practice Question Medium
Question 24
You are working on a Python script that processes large datasets using Pandas and NumPy. You want to use GitHub Copilot to generate a function that reads a CSV file, filters the rows where a specific column exceeds a threshold, and returns the filtered DataFrame. How would you craft an effective prompt to ensure GitHub Copilot generates code that meets your requirements?
-
A
"Write a Python function to read and process a CSV file."
-
B
"Write a Python function to manipulate data."
-
C
"Generate Python code that reads a CSV file, filters rows where the column 'value' is greater than 100, and returns the result as a DataFrame."
-
D
"Help me write Python code to analyze data using Pandas."
Reveal correct answer
Correct answer: C
A.
While this is somewhat specific, it lacks crucial details like the name of the column to filter or the threshold. This could result in GitHub Copilot generating code that reads the CSV but doesn't apply the necessary filtering operations.
B.
This prompt is too vague and leaves too much ambiguity. GitHub Copilot may generate code that manipulates data, but without specifying what kind of manipulation or which data, it is unlikely to be helpful.
C.
This prompt is clear, specific, and contains all the necessary details. GitHub Copilot will know that the CSV file should be read, filtered by a specific column and value, and returned as a DataFrame. It sets clear expectations and helps the model focus on the desired outcome.
D.
Although this prompt indicates that Pandas should be used, it still lacks the necessary details. GitHub Copilot may suggest generic data analysis code rather than the specific operation of filtering rows based on a threshold.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
