pandas is the table library. A pandas DataFrame is a spreadsheet you drive with code: rows and columns, a header, numbers read as numbers. This page maps a handful of pandas moves onto the Excel moves you already know. A table, AutoSum, AutoFilter, a PivotTable, and a lookup. We keep it shallow this week. Weeks 8 to 11 go deeper. Read each Predict card first, then press Shift+Enter (or click Run) to execute the cell. This is real Python, running in your browser.
A short table of AR invoices. There is no file to load. The rows below live in a string inside the page, and the first cell reads them into a DataFrame. Everything after that works on this one table.
io.StringIO, so you can focus on the pandas moves without a file getting
in the way. The shape is exactly what pd.read_csv("invoices.csv") would give you.Run the cells top to bottom. Each one does in pandas what you used to do with a click in Excel. The last cell is yours to experiment in.
That is the shallow end of pandas: read a table, total a column, filter rows, group and aggregate, and join two tables. Every one of those is a spreadsheet move you have already done by hand. The difference is that the pandas version is written once and runs the same way on seven rows or seven hundred thousand.
read_csv, a column with .sum(), a boolean-mask filter,
groupby, and a merge, are the ones you will reach for first. Get comfortable with the
Excel-to-pandas mapping now, and Project 2 is reading and grouping, not learning the syntax cold.
Two pandas functions on the same seven invoices, called df inside these boxes. The tests also call them on other tables, so the function has to use its argument, not the page's df.