Various operations
Perform common arithmetic and statistical operations like sum, median, or quartiles.
Example Data
Follow along with right out of the box example data. Copy following data in the information request of the agent you are working in.
Calculations help us transform the dataset for purposes of the intended analysis.
In this section, you’ll learn how to use Python to calculate key summary statistics and perform simple arithmetic operations on your dataset.
Sum, mean, and median
Excel
In Excel, you use functions like =SUM()
, =AVERAGE()
, and =MEDIAN()
to summarize a column.
t0 Prompt
What is the total amount?
Show me the average transaction size
Calculate the median transaction value
Code
The python code looks as follows:
Min, max, and quartiles
Excel
In Excel, you use =MIN()
, =MAX()
, or =QUARTILE()
to understand the spread of your data.
t0 Prompt
What is the smallest transaction?
Show the quartiles of the amount column
Give me the maximum value under Amount column
Code
The python code looks as follows:
Multiply, divide, subtract, or add values
Excel
In Excel, you use formulas like =A1*0.1
or =A1-B1
to calculate taxes, net income, or margins.
t0 Prompt
Add 10% adjustment to all transactions
Divide amount by 1 million
Subtract 500,000 from each value under Amount column
Code
The python code looks as follows:
Function | Description / Code example |
---|---|
sum() | transactions["Amount"].sum() |
mean() | transactions["Amount"].mean() |
median() | transactions["Amount"].median() |
quantile(0.25) | First quartile |
quantile(0.75) | Upper quartile |
min() / max() | Smallest or largest value |
column * 1.10 | Multiply (e.g. for taxes or markup) |
column - 500_000 | Subtract fixed amount |
column / 1_000_000 | Convert to millions |