Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Descriptive Stats from .csv file

by talexb (Canon)
on Jan 30, 2014 at 14:39 UTC ( #1072682=note: print w/replies, xml ) Need Help??

in reply to Descriptive Stats from .csv file

I would load the data into a database (sqlite is a great choice) and have the database do the work.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Replies are listed 'Best First'.
Re^2: Descriptive Stats from .csv file
by CountZero (Bishop) on Jan 30, 2014 at 20:55 UTC
    Or work through DBD::CSV to use those CSV tables directly.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      Have you tried it?

        Without even trying to understand what was required, a lot is already possible with DBD::CSV.

        $ cat pm1072615.csv Month,Zone,Replicate,SpeciesA,SpeciesB,SpeciesC Sept,1,1,5,10,15 Sept,1,2,0,5,10 Sept,1,3,5,0,5 Sept,2,1,5,5,5 Sept,2,2,10,15,10 Sept,2,3,0,0,5 $ cat #!/usr/bin/perl use 5.14.2; use warnings; use DBI; my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_ext => ".csv/r", }); my $sth = $dbh->prepare (qq; select month, zone, replicate, avg (speciesa) from pm1072615 group by month,zone, replicate; ); $sth->execute; while (my $row = $sth->fetch) { printf "%-5s %3d %3d %8.5f\n", @$row; } $ perl Sept 2 1 5.00000 Sept 2 2 10.00000 Sept 1 1 5.00000 Sept 1 3 5.00000 Use of uninitialized value in printf at line 19. Sept 1 2 0.00000 Use of uninitialized value in printf at line 19. Sept 2 3 0.00000 $

        Enjoy, Have FUN! H.Merijn
Re^2: Descriptive Stats from .csv file
by vincent_veyron (Sexton) on Jan 31, 2014 at 11:39 UTC

    If you have postgresql on hand, then it's as easy as :

    create table data( month text, zone integer, replicate integer, speciesa integer, speciesb integer, speciesc integer); copy data from stdin with delimiter ','; sept,1,1,5,10,15 Sept,1,2,0,5,10 Sept,1,3,5,0,5 Sept,2,1,5,5,5 Sept,2,2,10,15,10 Sept,2,3,0,0,5 \. select month, zone, replicate, avg(speciesa), stddev(speciesa) from da +ta group by month,zone, replicate; month | zone | replicate | avg | stddev -------+------+-----------+------------------------+-------- Sept | 1 | 2 | 0.00000000000000000000 | Sept | 2 | 3 | 0.00000000000000000000 | Sept | 1 | 3 | 5.0000000000000000 | Sept | 2 | 2 | 10.0000000000000000 | sept | 1 | 1 | 5.0000000000000000 | Sept | 2 | 1 | 5.0000000000000000 | (6 lignes) : legal case, contract and insurance claim management software

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1072682]
[karlgoethebier]: good morning
[Corion]: Discipulus: Ah, so he's the one getting almost drowned all the time - waterpolo certainly is no sport for me ;)
[karlgoethebier]: Corion: buy enough coke and popcorn...
[marto]: Corion the cinema is a lot more expensive than I remember :P
Discipulus hates the smell of popcorn at cinemas..
[Corion]: marto: Yeah, most of the time, I prefer to watch stuff at home, where we can sit on the couch, order pizza and pause the movie. But for kids,...
[Corion]: ... I think the "cinema experience" is something of its own. But certainly, bringing an USB stick home is much easier ;-D

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2017-07-24 08:20 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (348 votes). Check out past polls.