Column Types and Cleaning in pandas

Built-in AI tutor. It can see the code in the cell you are working on and the error you got. It points at the line and asks questions. It does not write the answer.

Every pandas column has one type for all its rows. One stray piece of text makes the whole column text, called object, and then the math stops working. This page loads seven employee expense claims with the usual mess in the amount column, shows what pd.to_numeric(..., errors="coerce") fixes and what it quietly destroys, and cleans the column properly. Homework 7 hands you a bills file with the same problem.

The claims, as the expense system exported them

claim_idemployeecategoryamount
E-101AnaTravel1200.50
E-102BenMeals$45.10
E-103CyTravelN/A
E-104DiLodging 310 
E-105EdMeals(blank)
E-106FloTravel1,050.00
E-107GusLodging289.99
Look before you coerce. errors="coerce" turns anything it cannot read into NaN, a missing value, without telling you. Two of these claims are real money that coerce will throw away. Finding them before they vanish is the skill.

The notebook

Run the cells top to bottom. Each one uses names from the cells above it, so skipping one gives a NameError further down. Edit any cell and run it again.

Check yourself

Two functions for any messy amount column. Inside these boxes claims is the table above and pd is imported. The tests also run them on a different column.