Evals / tables / Filter and clean

Filter rows

From gdp.csv keep only the rows for China and save them as china.csv with the header.

normalsingledata-wranglingdeft sheet query

The task

The reference answer shows the job can be done with deft. It is not an agent run.

deft sheet query gdp.csv --sql "select * from gdp where [Country Name] = 'China'" -o china.csv

Input

gdp.csv 549.6 KB
Country NameCountry CodeYearValue
AfghanistanAFG20003521418059.923445
AfghanistanAFG20012813571753.8725324
AfghanistanAFG20023825701438.9996333
AfghanistanAFG20034520946818.545814
AfghanistanAFG20045224896718.67782
AfghanistanAFG20056203256538.709669
AfghanistanAFG20066971758282.293506
AfghanistanAFG20079747886187.393929
AfghanistanAFG200810109297047.543194
AfghanistanAFG200912416152732.056717
AfghanistanAFG201015856668555.833595
AfghanistanAFG201117805098206.314083
AfghanistanAFG201219907329777.587166
AfghanistanAFG201320146416757.598675
AfghanistanAFG201420497128555.69723
AfghanistanAFG201519134221644.732494
AfghanistanAFG201618116572395.077213
AfghanistanAFG201718753456497.815865
AfghanistanAFG201818053222687.412624
AfghanistanAFG201918799444490.11278
AfghanistanAFG202019955929052.149597
AfghanistanAFG202114266499429.874573
AfghanistanAFG202214502158192.090395

Showing 24 of 4985 rows.

Reference output

china.csv 2.1 KB
Country NameCountry CodeYearValue
ChinaCHN196059716249310.97416
ChinaCHN196150056685957.35899
ChinaCHN196247209186415.35554
ChinaCHN196350706614526.14723
ChinaCHN196459708125203.86431
ChinaCHN196570436008642.42514
ChinaCHN196676720005491.89641
ChinaCHN196772881364882.49088
ChinaCHN196870846276051.47272
ChinaCHN196979705614854.76736
ChinaCHN197092602634891.65894
ChinaCHN197199800593790.98865
ChinaCHN1972113689308020.34328
ChinaCHN1973138543170458.06406
ChinaCHN1974144188970821.072
ChinaCHN1975163429530659.63803
ChinaCHN1976153939265947.7752
ChinaCHN1977174935933078.6625
ChinaCHN1978149540752829.26828
ChinaCHN1979178280594413.0435
ChinaCHN1980191149211575.0
ChinaCHN1981195866382432.53967
ChinaCHN1982205089699858.7786

Showing 24 of 65 rows.

How a result is judged (1 check)
  • csv: file = "china.csv", columns = 4, contains = ["China"], absent = ["Afghanistan"]

Runs

CodexWithout deftPassed2026-11-07

Time
12s
New tokens
5.9k
Total input
40.3k
Output tokens
0.4k
Commands
2
Failed
0

Trace

  1. I’ll inspect the CSV header and filter the China rows into `china.csv` in the current directory.

  2. pwd && rg --files -g 'gdp.csv' -g 'china.csv'
    output
    gdp.csv
  3. head -n 4 gdp.csv && python3 - <<'PY' import csv from pathlib import Path src=Path('gdp.csv') with src.open(newline='', encoding='utf-8-sig') as f: reader=csv.reader(f) rows=list(reader) if not rows: raise SystemExit('gdp.csv is empty') header=rows[0] # Identify the country field by common header names. normalized=[x.strip().lower() for x in header] choices=('country','country name','nation','economy') idx=next((normalized.index(c) for c in choices if c in normalized), None) if idx is None: raise SystemExit(f'Could not identify country column in header: {header}') with Path('china.csv').open('w', newline='', encoding='utf-8') as out: writer=csv.writer(out) writer.writerow(header) writer.writerows(row for row in rows[1:] if len(row)>idx and row[idx].strip().casefold()=='china') PY wc -l china.csv && head -n 3 china.csv
    output
    Country Name,Country Code,Year,Value
    Afghanistan,AFG,2000,3521418059.923445
    Afghanistan,AFG,2001,2813571753.8725324
    Afghanistan,AFG,2002,3825701438.9996333
          65 china.csv
    Country Name,Country Code,Year,Value
    China,CHN,1960,59716249310.97416
    China,CHN,1961,50056685957.35899
  4. Created [china.csv](china.csv) with the header and all 64 China data rows.

Output

china.csv 2.2 KB
Country NameCountry CodeYearValue
ChinaCHN196059716249310.97416
ChinaCHN196150056685957.35899
ChinaCHN196247209186415.35554
ChinaCHN196350706614526.14723
ChinaCHN196459708125203.86431
ChinaCHN196570436008642.42514
ChinaCHN196676720005491.89641
ChinaCHN196772881364882.49088
ChinaCHN196870846276051.47272
ChinaCHN196979705614854.76736
ChinaCHN197092602634891.65894
ChinaCHN197199800593790.98865
ChinaCHN1972113689308020.34328
ChinaCHN1973138543170458.06406
ChinaCHN1974144188970821.072
ChinaCHN1975163429530659.63803
ChinaCHN1976153939265947.7752
ChinaCHN1977174935933078.6625
ChinaCHN1978149540752829.26828
ChinaCHN1979178280594413.0435
ChinaCHN1980191149211575.0
ChinaCHN1981195866382432.53967
ChinaCHN1982205089699858.7786

Showing 24 of 65 rows.

CodexWith deft, skill installedPassedRead the skillUsed deft2026-11-07

Time
19s
New tokens
9.2k
Total input
101.1k
Output tokens
0.6k
Commands
6
Failed
0

Trace

  1. I’ll inspect the CSV and write the China rows with the original header to `china.csv` in the current directory.

  2. cat .agents/skills/deft/SKILL.md
    output
    ---
    name: deft
    description: "Use deft first for any simple, direct operation on local files, whatever the type: convert, read, extract, edit, compress, merge, split, compare or inspect. Try it before writing a script or one-liner. If unsure, run deft find; if it says no command does this, use another tool. Not for programming work: to read, write or change source code, skip it."
    ---
    
    # deft
    
    One local command for file jobs. Prefer it over writing Python or shell scripts.
    
    Syntax: `deft <group> <command> [inputs] [-o output] [--options]`
    
    Groups:
    - `pdf`: Merge, split, compress, encrypt, forms, OCR, compare, convert
    - `image`: Resize, crop, convert, compress, filters, montage, OCR
    - `video`: Trim, crop, speed, convert, compress, GIF, frames (ffmpeg)
    - `audio`: Convert, trim, merge, fade, speed, tag, normalize (ffmpeg)
    - `doc`: Word/ODT/RTF: to text, Markdown, HTML, PDF; find and replace
    - `slides`: PowerPoint: extract text, Markdown outline, PDF handout
    - `data`: JSON/YAML/TOML/XML: convert, query with jq syntax, merge, diff
    - `sheet`: Excel/CSV/ODS tables: filter, sort, join, pivot, convert
    - `md`: Markdown to PDF, HTML, Word, EPUB; table of contents
    - `html`: HTML to Markdown, text, Word, PDF; screenshots
    - `epub`: E-books: info, to text, Markdown and PDF
    - `email`: EML files: headers, text, attachments
    - `contact`: VCF address books: to and from CSV
    - `calendar`: ICS calendars: to and from CSV
    - `gps`: GPX and KML tracks: convert, distance and time
    - `youtube`: Info, downlo
    … 849 more characters
  3. deft find "filter CSV rows by a column value"
    output
    sheet filter     sheet -> sheet   Keep matching rows: --where "age > 30 and city = 'Oslo'"
    sheet pivot      sheet -> sheet   Pivot table: --rows city --columns year --values sales
    sheet info       sheet -> report  Sheet names, rows, columns
    sheet transpose  sheet -> sheet   Swap rows and columns
    sheet stats      sheet -> report  Per-column counts, empties, min, max, mean, sum
  4. rg --files -g 'gdp.csv' -g '*.csv'
    output
    gdp.csv
  5. deft sheet filter --help
    output
    deft sheet filter - Keep matching rows: --where "age > 30 and city = 'Oslo'"
    
    Usage: deft sheet filter <sheet>... [-o <sheet|dir>] [options]
    In: sheet (each handled separately)   Out: sheet (default <name>.filtered.<ext>)
    Compare with = != < <= > >=, contains, startswith, endswith, in (a, b), ~ 'regex'.
    Join with and, or, not, parentheses. Also: col is empty, col is not empty.
    Text comparison ignores case. Quote names with spaces: `Unit price` > 3.
    
    Options:
      --where <text>               Condition on columns (required)
      --sheet <text>               Sheet name or number (default: first)
      --to <csv|xlsx|json>         Output format (default: like the input)
    Common: -o --force --dry-run --json -j   (deft help common)
    
    Examples:
      deft sheet filter people.csv --where 'age > 30' -o older.csv
      deft sheet filter people.xlsx --where "name in (Ada, Sam)" --to csv -o some.csv
    
    Result fields: rows, columns
  6. head -n 3 gdp.csv
    output
    Country Name,Country Code,Year,Value
    Afghanistan,AFG,2000,3521418059.923445
    Afghanistan,AFG,2001,2813571753.8725324
  7. deft sheet filter gdp.csv --where \"'Country Name' = 'China'\" -o china.csv
    output
    ok sheet.filter gdp.csv -> china.csv  64 rows x 4 columns  0.01s
  8. Saved the 64 China rows, including the header, to [china.csv](china.csv).

Output

china.csv 2.1 KB
Country NameCountry CodeYearValue
ChinaCHN196059716249310.97416
ChinaCHN196150056685957.35899
ChinaCHN196247209186415.35554
ChinaCHN196350706614526.14723
ChinaCHN196459708125203.86431
ChinaCHN196570436008642.42514
ChinaCHN196676720005491.89641
ChinaCHN196772881364882.49088
ChinaCHN196870846276051.47272
ChinaCHN196979705614854.76736
ChinaCHN197092602634891.65894
ChinaCHN197199800593790.98865
ChinaCHN1972113689308020.34328
ChinaCHN1973138543170458.06406
ChinaCHN1974144188970821.072
ChinaCHN1975163429530659.63803
ChinaCHN1976153939265947.7752
ChinaCHN1977174935933078.6625
ChinaCHN1978149540752829.26828
ChinaCHN1979178280594413.0435
ChinaCHN1980191149211575.0
ChinaCHN1981195866382432.53967
ChinaCHN1982205089699858.7786

Showing 24 of 65 rows.

CodexWith deft, skill as AGENTS.mdPassed2026-11-05

Time
16s
New tokens
6.2k
Total input
61.7k
Output tokens
0.6k
Commands
3
Failed
0

Trace

  1. I’ll inspect the CSV header and country column, then write `china.csv` in the current directory with the header preserved.

  2. ls -la && head -n 5 gdp.csv
    output
    total 1112
    drwxr-xr-x@    4 user  staff     128 Nov  4 20:03 .
    drwx------@ 3397 user  staff  108704 Nov  4 20:03 ..
    -rw-r--r--@    1 user  staff    1486 Nov  4 20:03 AGENTS.md
    -rw-r--r--@    1 user  staff  562767 Nov  4 19:32 gdp.csv
    Country Name,Country Code,Year,Value
    Afghanistan,AFG,2000,3521418059.923445
    Afghanistan,AFG,2001,2813571753.8725324
    Afghanistan,AFG,2002,3825701438.9996333
    Afghanistan,AFG,2003,4520946818.545814
  3. deft sheet
    output
    deft sheet - commands (input -> output)
      info     sheet -> report    Sheet names, rows, columns
      convert  sheet -> sheet     Change format: --to csv|xlsx|json
      extract  sheet -> sheet     Take a sheet or range: --sheet, --range A1:D20
      merge    sheet... -> sheet  Stack tables; a shared header is kept once
      to-md    sheet -> md        Markdown table (first row is the header)
    More: deft sheet <command> --help
  4. python3 -c 'import csv; src=\"gdp.csv\"; dst=\"china.csv\"; f=open(src,newline=\"\",encoding=\"utf-8\"); reader=csv.DictReader(f); out=open(dst,\"w\",newline=\"\",encoding=\"utf-8\"); writer=csv.DictWriter(out,fieldnames=reader.fieldnames); writer.writeheader(); n=0 for row in reader: if row[\"Country Name\"] == \"China\": writer.writerow(row); n+=1 out.close(); f.close(); print(f\"Wrote {n} China rows with header to {dst}\")' && head -n 5 china.csv && wc -l china.csv
    output
    Wrote 64 China rows with header to china.csv
    Country Name,Country Code,Year,Value
    China,CHN,1960,59716249310.97416
    China,CHN,1961,50056685957.35899
    China,CHN,1962,47209186415.35554
    China,CHN,1963,50706614526.14723
          65 china.csv
  5. Saved [china.csv](china.csv) with the header and 64 China rows.

Output

Its files were not kept in this run. The last line of the trace is its own report.

Claude Opus 5.5Without deftPassed2026-11-07

Time
9s
New tokens
8.9k
Total input
42.2k
Output tokens
0.5k
Commands
0
Failed
0

Trace

    Output

    china.csv 2.2 KB
    Country NameCountry CodeYearValue
    ChinaCHN196059716249310.97416
    ChinaCHN196150056685957.35899
    ChinaCHN196247209186415.35554
    ChinaCHN196350706614526.14723
    ChinaCHN196459708125203.86431
    ChinaCHN196570436008642.42514
    ChinaCHN196676720005491.89641
    ChinaCHN196772881364882.49088
    ChinaCHN196870846276051.47272
    ChinaCHN196979705614854.76736
    ChinaCHN197092602634891.65894
    ChinaCHN197199800593790.98865
    ChinaCHN1972113689308020.34328
    ChinaCHN1973138543170458.06406
    ChinaCHN1974144188970821.072
    ChinaCHN1975163429530659.63803
    ChinaCHN1976153939265947.7752
    ChinaCHN1977174935933078.6625
    ChinaCHN1978149540752829.26828
    ChinaCHN1979178280594413.0435
    ChinaCHN1980191149211575.0
    ChinaCHN1981195866382432.53967
    ChinaCHN1982205089699858.7786

    Showing 24 of 65 rows.

    Claude Opus 5.5With deft, skill installedPassedRead the skillUsed deft2026-11-07

    Time
    37s
    New tokens
    12.2k
    Total input
    111.8k
    Output tokens
    1.2k
    Commands
    0
    Failed
    0

    Trace

      Output

      ---
      name: deft
      description: "Use deft first for any simple, direct operation on local files, whatever the type: convert, read, extract, edit, compress, merge, split, compare or inspect. Try it before writing a script or one-liner. If unsure, run deft find; if it says no command does this, use another tool. Not for programming work: to read, write or change source code, skip it."
      ---
      
      # deft
      
      One local command for file jobs. Prefer it over writing Python or shell scripts.
      
      Syntax: `deft <group> <command> [inputs] [-o output] [--options]`
      
      Groups:
      - `pdf`: Merge, split, compress, encrypt, forms, OCR, compare, convert
      - `image`: Resize, crop, convert, compress, adjust, montage, OCR
      - `video`: Trim, merge, convert, compress, subtitles, GIF, frames (ffmpeg)
      - `audio`: Convert, trim, normalize, denoise, cut silence (ffmpeg)
      - `doc`: Word/ODT/RTF: to text, Markdown, HTML, PDF; find and replace
      - `slides`: PowerPoint: extract text, Markdown outline
      - `sheet`: Excel/CSV/ODS tables: SQL query, pivot, merge, split, convert
      - `json`: JSON: convert, format, merge, diff, validate
      - `toml`: TOML: convert, format, merge, diff, validate
      - `xml`: XML: convert, format, merge, diff, validate
      - `yaml`: YAML: convert, format, merge, diff, validate
      - `md`: Markdown to PDF, HTML, Word, EPUB; table of contents
      - `html`: HTML to Markdown, text, Word and PDF
      - `epub`: E-books: info, to text, Markdown and PDF
      - `gps`: GPX and KML tracks: convert, distance and time
      - `qr`: Create QR codes and barcodes; read QR codes
      
      How to use it:
      1. Run `deft <group>` to list commands, or `deft find "<what you want>"` to search. If it says `no command does this`, use another tool.
      2. Run `deft <group> <command> --help` for options and examples.
      3. `deft convert <in> -o <out.ext>` converts between formats by extension.
      4. Results are one line starting with `ok`, `partial` or `error`; add `--json` to parse them. Errors include a `hint:` with the fix.
      
      Inputs are never overwritten; pass `--force` or `--in-place` to allow it. Globs and directories work as inputs; several inputs run in parallel.
      
      If `deft` is not installed, ask the user, then follow https://github.com/firstprayer/deft/blob/main/docs/INSTALL.md
      
      china.csv 2.1 KB
      Country NameCountry CodeYearValue
      ChinaCHN196059716249310.97416
      ChinaCHN196150056685957.35899
      ChinaCHN196247209186415.35554
      ChinaCHN196350706614526.14723
      ChinaCHN196459708125203.86431
      ChinaCHN196570436008642.42514
      ChinaCHN196676720005491.89641
      ChinaCHN196772881364882.49088
      ChinaCHN196870846276051.47272
      ChinaCHN196979705614854.76736
      ChinaCHN197092602634891.65894
      ChinaCHN197199800593790.98865
      ChinaCHN1972113689308020.34328
      ChinaCHN1973138543170458.06406
      ChinaCHN1974144188970821.072
      ChinaCHN1975163429530659.63803
      ChinaCHN1976153939265947.7752
      ChinaCHN1977174935933078.6625
      ChinaCHN1978149540752829.26828
      ChinaCHN1979178280594413.0435
      ChinaCHN1980191149211575.0
      ChinaCHN1981195866382432.53967
      ChinaCHN1982205089699858.7786

      Showing 24 of 65 rows.

      Claude CodeWithout deftNot run yet

      Claude CodeWith deftNot run yet