Model df.isna().sum(), the first check on any new table.
What to build
A program that counts missing values per column and complete rows.
Requirements
- Print
NAME: Mfor each column in header order (M missing values), thentotal missing: Tandcomplete rows: C of N.
Input
Line 1: the header. Line 2: n. Then n rows, values separated by commas; an empty value is missing.
Output
One line per column, then two lines.
Constraints
0 ≤ n ≤ 100; 1 ≤ columns ≤ 10.
Example
Input:
name,age
5
Ada,36
Rahim,
,29
Omar,
Lena,41
Output:
name: 1
age: 2
total missing: 3
complete rows: 2 of 5
Why it works
isna gives one boolean per cell and summing a column counts its gaps; a row is complete when its row of booleans holds no True, which is what dropna keeps.
Examples
Example 1 · Input
name,age 5 Ada,36 Rahim, ,29 Omar, Lena,41
Expected output
name: 1 age: 2 total missing: 3 complete rows: 2 of 5
Example 2 · Input
a,b,c 2 1,2,3 4,5,6
Expected output
a: 0 b: 0 c: 0 total missing: 0 complete rows: 2 of 2
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
An empty cell is missing; count them column by column.
Hint 2
A row is complete when none of its cells is empty.
Solution
Show one correct solution (try it yourself first)
header = input().split(",")
n = int(input())
rows = [input().split(",") for _ in range(n)]
total = 0
for i, name in enumerate(header):
m = sum(1 for row in rows if row[i] == "")
total += m
print(f"{name}: {m}")
print(f"total missing: {total}")
print(f"complete rows: {sum(1 for row in rows if '' not in row)} of {n}")