Three lists that belong together
You could keep names in one list, cities in another and marks in a third, and rely on position 2 meaning the same student in all three. Sort one of them and that promise is broken silently, taking every conclusion with it.
A DataFrame is a table: columns with names, rows that stay together, and one row per student.
pd.DataFrame(data) where data is a dictionary. Each key becomes a column heading; each list becomes that column's values. The lists must be the same length, because they are rows read across.Printing one shows the table with a numbered column down the left. Those numbers are the index — pandas puts them there for you, and they are how a row is identified once the order changes.
students["marks"].It keeps the index alongside the values, so a mark never loses track of which row it came from. Printed, it shows the index down the left and a footer saying what it is called and what kind of values it holds.
A DataFrame is a collection of Series that share one index. Almost everything you do to a whole table can also be done to one column, and the answers come back in the same shape.
students["marks"] hands back a Series: one column, on its own.students[["marks"]] hands back a DataFrame that happens to have one column in it.They hold the same numbers and they are not the same kind of thing, which shows up the moment you ask either of them a question. The average of a Series is a number. The average of a DataFrame is a Series — one answer per column, even when there is only one column.
students.shape gives a pair: rows first, columns second. Four students in three columns is (4, 3).It is a fact about the table, not a job it performs, so it takes no brackets — the same rule as
.shape on a NumPy array in problem 18.What you are building
Build the programme
Your plan
The steps still to place
The whole programme is laid out below. Five pieces are missing. Two of them come back with a perfectly good number that counts the wrong thing, and one changes what kind of object you are holding without changing any of the numbers in it.
Leave nothing on "choose…". A wrong pick does not always cause an error — sometimes it just prints something you did not expect, which is the harder kind of mistake to spot.
Run and read
Here is the whole programme. The marks are yours to change, and the table grows or shrinks to match. Watch the shape.