Building a DataFrame
Write build_frame(names, scores) that returns a DataFrame with a "name" column and a "score" column, then returns its shape as a list.
The test checks the shape, so return the DataFrame and let the harness read off it.
Examples
The score column holds the values you passed in
- Input
- build_frame(["a", "b"], [7, 8])
- Output
- 15
Hints
Hint 1
Work directly with the arguments names, scores and return the result rather than printing it.
Hint 2
A common slip here: built rows instead of columns.
Requirements
names: a list of stringsscores: a list of numbers, the same lengthReturn a DataFrame with columns "name" and "score".
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Where this shows up
8 employers weight this skill
2 big tech firms, 2 frontier labs, 1 AI product company, 1 defense company, 1 enterprise vendor, 1 quant fund. Top match scores 63.
import pandas as pd
def build_frame(names, scores):
"""
Build a two-column DataFrame.
Args:
names: a list of strings
scores: a list of numbers, the same length
Returns:
A DataFrame with columns "name" and "score".
"""
# YOUR CODE HERE
pass
def _score_total(names, scores):
"""Total of the score column of the frame that was built."""
return float(build_frame(names, scores)["score"].sum())