Python lesson
A first look at any table
8 orders, an average of 57.375, from 15 to 140. Two stores. And Earbuds earned the most. .idxmax() gives the label of the biggest value, not the value itself.
Try this lesson free →Example
.describe() sums up a number column, .unique() lists the different values, and .idxmax() names the biggest:
print(df["Revenue"].describe())
print(df["Store"].unique())
df.groupby("Product")["Revenue"].sum().idxmax()count 8.0
mean 57.375
std 44.2652314382938
min 15.0
25% 28.5
50% 37.5
75% 78.75
max 140.0
Name: Revenue
['Lagos', 'Abuja']
'Earbuds'Key points
.describe()Count, average, spread, smallest, quartiles and biggest, in one go.
.unique()Every different value, once each.
.idxmax()The label of the biggest value. .idxmin() for the smallest.
Check firstSize, columns, then these: surprises show up before you report them.
Get to know a file with .describe(), .unique() and .idxmax().
Practice
1. Build a line that sums up the Revenue column.
df["Revenue"].describe()2. Build a line that names the product with the most revenue.
df.groupby("Product")["Revenue"].sum().idxmax()3. Sum up the Qty column in one go.
df["Qty"].describe()4. Show the different products, once each.
df["Product"].unique()5. Show the day with the least revenue.
df.groupby("Day")["Revenue"].sum().idxmin()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 →