pandas: Summarise a column

Model the most common pandas call on a column: a quick summary of its values.

What to build

A program that summarises one numeric column, like part of Series.describe().

Requirements

  • Print count: N, sum: S, mean: M (two decimals), min: A and max: B.

Input

Line 1: n. Line 2: n whole numbers separated by spaces.

Output

Five lines.

Constraints

1 ≤ n ≤ 1000; |value| ≤ 10^6.

Example

Input:

4
120 340 510 90

Output:

count: 4
sum: 1060
mean: 265.00
min: 90
max: 510

Why it works

Each figure is one pass over the whole column, which is what pandas does for count, sum, mean, min and max on a Series.

Examples

Example 1 · Input
4
120 340 510 90
Expected output
count: 4
sum: 1060
mean: 265.00
min: 90
max: 510
Example 2 · Input
3
1 2 2
Expected output
count: 3
sum: 5
mean: 1.67
min: 1
max: 2

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Read the values into a list, then use len, sum, min and max.

Hint 2

The mean is the sum divided by the count; format it with two decimals.

Solution

Show one correct solution (try it yourself first)
n = int(input())
values = list(map(int, input().split()))
print("count:", n)
print("sum:", sum(values))
print(f"mean: {sum(values) / n:.2f}")
print("min:", min(values))
print("max:", max(values))

Lesson: Why pandas, and how this course runs it →