Clean Messy Amount and Date Strings From a Merchant Settlement File
Last updated: November 29, 2026
Quick Overview
A merchant settlement file stores amounts as strings like "$1,234.56", "(45.00)" and "12.50 CR", and dates in mixed formats. Write pandas code that parses them into numeric amounts and datetimes and flags rows that failed to parse.
Capital One
November 29, 20260
0
0 solved
A merchant settlement file stores amounts as strings like "$1,234.56", "(45.00)" and "12.50 CR", and dates in mixed formats. Write pandas code that parses them into numeric amounts and datetimes and flags rows that failed to parse.
Capital One's merchant and commercial payments teams receive partner files with inconsistent formatting, and analysts must clean them without silently corrupting dollar values. The reviewer looks for explicit parsing rules, negative amount conventions used in accounting, and a parse-failure flag instead of dropping rows.
What the Interviewer Expects
- Handles currency symbols, thousands separators and codes
- Treats parentheses, leading minus and CR suffix as negatives
- Maps known null tokens to NaN
- Rejects malformed numbers instead of guessing
- Parses mixed date formats with errors coerced and flagged
- Raises the ambiguity of day-first versus month-first dates
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you detect that a partner switched to day-first dates?
- Would you use float or Decimal for these amounts and why?
- How would you report parse failures back to the partner?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
- Columns:
amount_raw,posted_raw(strings, possibly missing). - Conventions:
(45.00)and45.00 CRmean credits, so negative.USD 12means 12. - Null tokens: empty,
N/A,NA,NULL,-....
Approach
Write a scalar parse_amount that normalizes case, detects sign markers, strips everything except digits and the decimal point, and rejects strings with zero or multiple decimal points. Apply it with...