py-02-csv-groupby
1.000
Proposed solution
```python
def group_sum(csv_text: str, key_col: str, val_col: str) -> dict[str, float]:
lines = [line for line in csv_text.split('\n') if line.strip()]
if not lines:
return {}
header = lines[0].split(',')
key_index = header.index(key_col)
val_index = header.index(val_col)
result = {}
for line in lines[1:]:
parts = line.split(',')
key = parts[key_index]
try:
value = float(parts[val_index])
result[key] = result.get(key, 0) + value
except ValueError:
pass # Ignore rows where val_col is not numeric
return result
```Test output (stdout)
........ [100%] 8 passed in 0.01s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.