Operations & Basic Statistics
Pandas makes it easy to run calculations like sum, average, min, and max on a single column. It's hugely useful for things like sales reports, student score reports, expense trackers, and calculating inventory value.
python
import pandas as pd
df = pd.DataFrame({
"Product": ["Tea", "Coffee", "Cake"],
"Price": [1200, 1800, 2500],
"Qty": [3, 2, 1]
})
df["Total"] = df["Price"] * df["Qty"]
print(df)
print("
Total Sales:", df["Total"].sum())
print("Average Order Value:", df["Total"].mean())
print("Highest Sale:", df["Total"].max())df["Total"] = df["Price"] * df["Qty"] multiplies two columns row by row and adds the result as a new column. With Pandas, you don't need to write a loop — a column-level operation like this happens in a single line.
You should see
Product Price Qty Total 0 Tea 1200 3 3600 1 Coffee 1800 2 3600 2 Cake 2500 1 2500 Total Sales: 9700 Average Order Value: 3233.3333333333335 Highest Sale: 3600Info
Your columns need to be a number type. If Price contains text with commas like "1,200", you'll need to convert it to a number before you can calculate with it.