csv_plus v1.2.0
pub.dev GitHub

Query and group CSV data

Work on the data directly instead of writing loops around a list of lists.

Install#

dart pub add csv_plus
import 'package:csv_plus/csv_plus.dart';

Filter and sort#

final table = CsvTable.parse('name,age,city\nAlice,30,NYC\nBob,25,LA\nEve,35,NYC');

// Filter, returning a new table.
final adults = table.where((row) => (row['age'] as int) >= 30);

// Sort in place, stable.
table.sortBy('age');

// Or take a sorted copy and leave the source alone.
final byAge = table.sortedBy('age');

Aggregate#

table.avg('age'); // 30.0
table.sum('age'); // 90
table.max('age'); // 35

Group#

final byCity = table.groupBy('city');
// {NYC: CsvTable, LA: CsvTable}

byCity['NYC']!.avg('age'); // 32.5

Back out again#

print(table.toCsv());
print(table.toFormattedString()); // aligned columns, good for a terminal