Python Lab
Analyze data with Python and pandas right in your browser, using JupyterLite. Nothing to install.
The console below creates a sample sales dataset in the variable df. Copy each step, paste it into the console and press Shift + Enter.
Guide: your first sales analysis
1
First rows
See the first five sales and the available columns.
df.head()
2
Types and summary
Check the data types and basic statistics of the numeric columns.
df.info()
df.describe()
3
Filter
Select only Website sales with a total above $1,000.
df[(df["channel"] == "Website") & (df["total_amount"] > 1000)]
4
Group
Count sales and add up revenue by channel, highest first.
(df.groupby("channel")["total_amount"]
.agg(sales="count", revenue="sum")
.sort_values("revenue", ascending=False))
5
Monthly series
Add up revenue by month to see the trend over the year.
df.set_index("date")["total_amount"].resample("MS").sum().round(2)
6
Challenge
Which category has the highest average ticket (average amount per sale)? Write the code yourself and compare with a classmate.
# your answer here
