← Python course

Lesson 09

Working with data

pandas — handling real, messy, spreadsheet-shaped data in code.

Everything you've built so far works on small, tidy lists. Real data — scores, dates, survey answers — comes in big messy tables. pandas is the tool nearly every Python data project uses to handle that.

This lesson loads a bigger package, so the first run will take a little longer than usual.

Loading editor…

A DataFrame is a table — rows and columns, like a spreadsheet, but you can filter, sort, and calculate on it with code instead of clicking around.

Loading editor…

df["score"] pulls out a single column. .mean() is a method that computes the average — no loop required, pandas does it internally. df[df["score"] > 85] is a filter: "give me only the rows where the score column is above 85." Read it as a sentence and it makes sense.

Sorting is just as direct:

Loading editor…

Your turn

Build a small DataFrame of 4–5 made-up students with a score column. Print only the students who scored above the average. Hint: you can use df["score"].mean() inside your filter.

Loading editor…

One lesson left — and it's yours to design. Next: your final project.