This question evaluates proficiency in code refactoring, robustness, input validation, unit testing, environment specification, and complexity analysis for Python data-processing workflows (pandas), within the Coding & Algorithms domain for Data Scientist roles.

You are reviewing a short Python script that sums a numeric column from a CSV using pandas. Your tasks are to identify problems, refactor into a small, testable module, add tests, define an environment, and explain design choices and complexity trade-offs.
# script.py
import pandas as pd
DATA_PATH = 'data.csv'
result = None
def compute_total(col):
df = pd.read_csv(DATA_PATH)
total = 0
for x in df[col]:
if x == '':
total += 0
else:
total += float(x)
print(total)
compute_total('amount')
Login required