Parsing rows and the bool('False') trap

Beginner Python for Data Science
Created by Best · 24.06.2026 at 14:03 UTC

Now combine the two ideas: a function that turns one raw row of strings into properly typed values.

def parse_employee_row(row):
    return {
        "id": int(row["id"]),
        "dept": row["dept"],
        "salary": float(row["salary"]),
        "full_time": row["full_time"] == "1",
    }

Each line converts a string to its proper type: int(...) for the id, float(...) for the salary, and a comparison row["full_time"] == "1" that yields a real True or False. You then call it on every row, after which the rest of your program can trust the data is clean:

clean = [parse_employee_row(r) for r in rows]
print(clean[0]["salary"] + 1000)   # arithmetic works now

One booby-trap deserves a flashing light: never write bool("False") to parse a boolean. In Python any non-empty string is "truthy", so bool("False") is True — the exact opposite of what you meant. Always compare explicitly, as in row["flag"] == "1" or == "True".

Be deliberate about missing values too: an empty string is not the same as None; decide which you mean and convert accordingly. These boundary habits matter because almost every data bug is a type bug that slipped in early — a number left as text, a 0 standing in for "missing" that quietly lowers a mean.
and leads into “Lists as vectors: scaling and the dot product”.*

University approvals: 0
Related cards
Builds on Measurement scales and your first function · Python for Data Science
Next Lists as vectors: scaling and the dot product · Python for Data Science
Tasks
Question 1

Read three lines from stdin: an id (int), a salary (float), and a full-time flag (1 or 0). Print True if the person is full-time AND earns at least 50000, else False.

Example input:

7
95000
1

Expected output:

True
3 test cases will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Question 2

What is the value of bool("False") in Python?

Card Info
  • Topic: Python for Data Science
  • Difficulty: Beginner
  • Completed: 0 users
Creator
Best
Best
BestBuddy