df 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

Df #

pub package Build Status Coverage Status

A dataframe for Dart

Usage #

Create #

From csv:

   final df = await DataFrame.fromCsv("dataset/stocks.csv");

Note: the type of the records are infered from the data. The first line of the csv must contains the headers for the column names. Optional parameters:

dateFormat: the string format of the date: reference. Ex: MMM dd yyyy

timestampCol: the column to be treated as a timestamp. Ex: timestamp

timestampFormat: the format of the timestamp: seconds, milliseconds or microseconds. Ex: TimestampFormat.microseconds

verbose: set to true to print some info

From records:

   final rows = <Map<String, dynamic>> rows[
      <String, dynamic>{"col1": 21, "col2": "foo", "col3": DateTime.now()},
      <String, dynamic>{"col1": 22, "col2": "bar", "col3": DateTime.now()},
   ];
   final df = DataFrame.fromRows(rows);

Select #

   final List<Map<String, dynamic>> rows = df.rows;
   // select a subset of rows
   final List<Map<String, dynamic>> rows = df.subset(0,100);
   /// select records for a column
   final List<double> values = df.colRecords<double>("col2");
   /// select list of records
   final List<List<dynamic>> records = df.records;

Mutate #

Add data:

   // add a row
   df.addRow(<String,dynamic>{"col1": 1, "col2": 2.0});
   // add a line of records
   df.addRecord(<dynamic>[1, 2.0]);

Remove data:

   df.removeFirstRow();
   df.removeLastRow();
   // remove the third row
   df.removeRowAt(2);
   // limit the dataframe to 100 rows starting from index 30
   df.limit(100, startIndex: 30);

Copy a dataframe:

   // get a new dataframe from the existing one
   final DataFrame df2 = df.copy_();
   // get a new dataframe with limited data
   final DataFrame df2 = df.limit_(100);

Count #

Nulls and zeros:

   final int n = df.countNulls_("col1");
   final int n = df.countZeros_("col1");

Columns:

   final int mean = df.mean("col1");
   final int sum = df.sum("col1");
   final int max = df.max("col1");
   final int min = df.min("col1");

Info #

   final int numRecords= df.length;
   final List<DataFrameColumn> cols = df.columns;
   final List<String> colNames = df.columnsNames;
   // print info and sample data
   df.head();
   // like head with a bit more details
   df.show();

Conventions #

All the dataframe operations are inplace. All the methods that return objects end with an underscore. Example:

   // inplace
   df.limit(30);
   // get a new dataframe with limited data
   final DataFrame df2 = df.limit_(30);

Vocabulary conventions:

  • A row is a map of key/values pair
  • A record is a single cell value
  • An index is a row position
  • An indice is a column position

Changelog #

0.2.1 #

  • Improve the tests
  • Improve the docs

0.2.0 #

  • Add support for timestamp formats
  • Update dependencies

0.1.0 #

Initial

example/main.dart

import 'package:df/df.dart';

Future<void> main() async {
  final df = await DataFrame.fromCsv("dataset/stocks.csv",
      dateFormat: "MMM dd yyyy", verbose: true);
  df.show();
  print(df.columns);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  df: ^0.2.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:df/df.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
64
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on May 25, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
extra_pedantic ^1.1.1+3 1.2.0
jiffy ^3.0.1 3.0.1
meta ^1.1.8 1.1.8
ml_linalg ^12.7.1 12.10.0
pedantic ^1.8.0 1.9.0
Transitive dependencies
injector 1.0.8
intl 0.16.1
matcher 0.12.6
path 1.7.0
quiver 2.1.3
stack_trace 1.9.3
xrange 0.0.8
Dev dependencies
test ^1.6.5
test_coverage ^0.4.0