Importing only specific lines from large csv file

CSV.jl has functionality for reading large CSV files in chunks already: Reading · CSV.jl

To do exactly what you ask, you could e.g. do something like this with skipto and limit, but using the chunk iterator might be a better solution.

julia> using CSV

julia> data = """
       a,b,c
       1,2,3
       4,5,6
       7,8,9
       totals: 12, 15, 18
       grand total: 45
       """
"a,b,c\n1,2,3\n4,5,6\n7,8,9\ntotals: 12, 15, 18\ngrand total: 45\n"

julia> file = CSV.File(IOBuffer(data);skipto=3, limit=2)
2-element CSV.File:
 CSV.Row: (var"a,b,c" = String7("4,5,6"),)
 CSV.Row: (var"a,b,c" = String7("7,8,9"),)

1 Like