BBampaa

Lessons › Python

Python lesson

Looking at a table

df.shape gives (rows, columns): 8 orders and 6 columns. len(df) counts just the rows. tail shows rows from the bottom, the opposite of head.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Before analysing a table, check its size and its columns:

print(df.shape)
print(len(df))
df.tail(2)

Output:

(8, 6)
8
Order Day Store Product Qty Revenue
6 O107 Fri Abuja Phone case 5 40
7 O108 Fri Lagos Earbuds 3 105

Key points

df.shape(rows, columns). No brackets after shape.
df.columnsThe names of every column.
df.tail(3)The last 3 rows. The opposite of head.

Checking size and columns first catches surprises, like a file that loaded with no rows.

Practice

Try each one in your head first, then open the answer.

1. Build a line that shows how many rows and columns df has.
df.shape
2. Build a line that shows the last 2 rows.
df.tail(2)
3. Show how many rows and columns df has.
df.shape
4. Show the last 3 rows of df.
df.tail(3)
5. Print how many rows df has.
print(len(df))

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed