Last active
January 20, 2022 11:46
-
-
Save caniko/51c5c98ccf3f5243c170eb27eb6014c6 to your computer and use it in GitHub Desktop.
Convert header + row data to Dart df
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:df/df.dart'; | |
import 'package:grizzly_io/io_loader.dart'; // to parse CSV string | |
DataFrame _convertHeaderRowDataToDf(List<List<String>> headerRowData) { | |
List<String> headers = headerRowData[0]; | |
List<Map<String, Object?>> mappedData = []; | |
for (int i = 1; i < headerRowData.length; i++) { | |
Map<String, Object?> mappedRow = {}; | |
headerRowData[i].asMap().forEach((int rowIndex, value) { | |
mappedRow[headers[rowIndex]] = value; | |
}); | |
mappedData.add(mappedRow); | |
} | |
return DataFrame.fromRows(mappedData); | |
} | |
DataFrame df = _convertHeaderRowDataToDf(parseCsv(utf8.decode(<csv bytes>))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment