NAME

PDL::IO::CSV - Load/save PDL from/to CSV file (optimized for speed and large data)

SYNOPSIS

use PDL;
use PDL::IO::CSV ':all';

my $pdl = rcsv2D('input.csv');
$pdl *= 2;
wcsv2D($pdl, 'double.csv');

my ($pdl1, $pdl2, $pdl3) = rcsv1D('input.csv', [0, 1, 6]);
wcsv1D($pdl1, 'col2.csv');
#or
$pdl2->wcsv1D('col2.csv');
$pdl2->wcsv1D('col2_tabs.csv', {sep_char=>"\t"});

DESCRIPTION

The traditional way of creating PDL piddle from CSV data is via rcols function.

my $pdl = rcols("data.csv", [1..4], { DEFTYPE=>double, COLSEP=>"," });

This module provides alternative implementation based on Text::CSV_XS which should be significantly faster than traditional approach.

PDL::IO::CSV supports reading CSV data and creating PDL piddle(s) as well as saving PDL data to CSV file.

FUNCTIONS

By default, PDL::IO::CSV doesn't import any function. You can import individual functions like this:

use PDL::IO::CSV qw(rcsv2D wcsv2D);

Or import all available functions:

use PDL::IO::CSV ':all';

rcsv1D

Loads data from CSV file into 1D piddles (separate for each column).

my ($pdl1, $pdl2, $pdl3) = rcsv1D($csv_filename_or_filehandle);
#or
my ($pdl1, $pdl2, $pdl3) = rcsv1D($csv_filename_or_filehandle, \@column_ids);
#or
my ($pdl1, $pdl2, $pdl3) = rcsv1D($csv_filename_or_filehandle, \%options);
#or
my ($pdl1, $pdl2, $pdl3) = rcsv1D($csv_filename_or_filehandle, \@column_ids, \%options);

Parameters:

Items supported in options hash:

rcsv2D

Loads data from CSV file into 2D piddle.

my $pdl = rcsv2D($csv_filename_or_filehandle);
#or
my $pdl = rcsv2D($csv_filename_or_filehandle, \@column_ids);
#or
my $pdl = rcsv2D($csv_filename_or_filehandle, \%options);
#or
my $pdl = rcsv2D($csv_filename_or_filehandle, \@column_ids, \%options);

Parameters and items supported in options hash are the same as by "rcsv1D".

wcsv1D

Saves data from one or more 1D piddles to CSV file.

wcsv1D($pdl1, $pdl2, $pdl3, $csv_filename_or_filehandle, \%options);
#or
wcsv1D($pdl1, $pdl2, $pdl3, $csv_filename_or_filehandle);
#or
wcsv1D($pdl1, $pdl2, \%options); #prints to STDOUT
#or
wcsv1D($pdl1, $pdl2);

# but also as a piddle method
$pdl1D->wcsv1D("file.csv");

NOTE: piddles piddles are instances of PDL::DateTime are exported by wcsv1D as ISO 8601 strings.

Parameters:

Items supported in options hash:

wcsv2D

Saves data from one 2D piddle to CSV file.

wcsv2D($pdl, $csv_filename_or_filehandle, \%options);
#or
wcsv2D($pdl, $csv_filename_or_filehandle);
#or
wcsv2D($pdl, \%options); #prints to STDOUT
#or
wcsv2D($pdl);

# but also as a piddle method
$pdl->wcsv2D("file.csv");

Parameters and items supported in options hash are the same as by "wcsv1D".

SEE ALSO

PDL, Text::CSV_XS

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

COPYRIGHT

2014+ KMX kmx@cpan.org