BuildlyBuildly
DashboardExercisesProfileHelp
Back to all

Practice: CSV I/O (basic)

Drills tagged with this skill, unpassed first. Pass them all to mark the skill ready for scenarios.

Module 2: Data Analytics

0/3 done
Exercises (0/3)
  • 1
    Parse a CSV String
    Context. A CSV string pulled from an API needs to be parsed into a DataFrame. Your task. Write parse_csv(csv_text) that takes a CSV-formatted string (header row present) and returns a DataFrame. Example. "a,b\n1,2\n3,4" → 2-row DataFrame with columns a and b. Notes. Use io.StringIO to wrap the string so pd.read_csv can read it like a file. Always has a header row.
    7 min· 10 XP
  • 2
    Serialize to a CSV String
    Context. After computing a report, ship it back as a CSV string (e.g., for download). Your task. Write to_csv_string(df) that returns the DataFrame serialized as a CSV string with header, without the index column. Example. A df with name/score → "name,score\nAlice,85\nBob,92\n". Notes. Include header. Skip the index column (otherwise pandas prepends an unnamed column with row numbers). Trailing newline is part of pandas' default output.
    7 min· 10 XP
  • 3
    Parse CSV and Filter
    Context. Parse a CSV of orders, then keep only the ones above a threshold amount. Your task. Write parse_and_filter(csv_text, min_amount) that parses the CSV and returns only rows where amount >= min_amount. Example. CSV of 4 orders with amounts [100, 30, 75, 10], min_amount=50 → rows with 100 and 75. Notes. Preserve row order from the CSV. min_amount higher than every value → empty DataFrame.
    7 min· 10 XP