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.shapeThe table's size as (rows, columns): (8, 6) means 8 rows and 6 columns. No brackets after shape.
len(df)How many rows df has, as one number.
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 counts the rows in df.
len(df)3. Build a line that shows the last 2 rows.
df.tail(2)4. Show how many rows and columns df has.
df.shape5. Show the last 3 rows of df.
df.tail(3)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 →