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 →Example
Before analysing a table, check its size and its columns:
print(df.shape)
print(len(df))
df.tail(2)(8, 6)
8
Order Day Store Product Qty Revenue
6 O107 Fri Abuja Phone case 5 40
7 O108 Fri Lagos Earbuds 3 105Key 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
1. Build a line that shows how many rows and columns df has.
df.shape2. Build a line that shows the last 2 rows.
df.tail(2)3. Show how many rows and columns df has.
df.shape4. 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 →