June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,10 @@
USING: csv io.encodings.utf8 kernel math.parser sequences ;
IN: rosetta-code.csv-manipulation
: append-sum ( seq -- seq' )
dup [ string>number ] map-sum number>string suffix ;
: csv-sums ( seq -- seq' )
[ 0 = [ "SUM" suffix ] [ append-sum ] if ] map-index ;
"example.csv" utf8 [ file>csv csv-sums ] [ csv>file ] 2bi

View file

@ -1,7 +1,7 @@
my $csvfile = './whatever.csv';
my $fh = open($csvfile, :r);
my @header = $fh.get.split(',');
my @csv = map {[.split(',')]}, $fh.lines;
my @csv = map {[.split(',')]>>.Num}, $fh.lines;
close $fh;
my $out = open($csvfile, :w);

View file

@ -1,5 +1,5 @@
use Text::CSV;
my $csvfile = './whatever.csv';
my @csv = Text::CSV.parse-file($file);
modify(@csv); # do whatever;
my @csv = Text::CSV.parse-file($csvfile);
# modify(@csv); # do whatever;
csv-write-file( @csv, :file($csvfile) );

View file

@ -0,0 +1,4 @@
>>filein: read/lines %file.csv
>>data: copy []
>>foreach item filein [append/only data split item ","]
; [["C1" "C2" "C3" "C4" "C5"] ["1" "5" "9" "13" "17"] ["2" "6" "10" "14" "18"] ["3" "7" "11" "15" "19"]["4" "8" "12" "16" "20"]]

View file

@ -0,0 +1,6 @@
>>forall data [either (index? data) = 1[
append data/1 "SUM"
][
append data/1 to string!
(to integer! data/1/1) + (to integer! data/1/2) + (to integer! data/1/3) + (to integer! data/1/4) + (to integer! data/1/5)
]]

View file

@ -0,0 +1,8 @@
>>foreach item data [append item/6 "^/" repeat c 5 [append item/:c ","]]
>> print data
C1, C2, C3, C4, C5, SUM
1, 5, 9, 13, 17, 45
2, 6, 10, 14, 18, 50
3, 7, 11, 15, 19, 55
4, 8, 12, 16, 20, 60
>>write fileout.csv form data

View file

@ -1,4 +1,4 @@
import delimited input.csv, clear
import delim input.csv, clear
replace c5=c3+c4
drop if mod(c3,3)==0
export delimited using output.csv, replace
export delim output.csv, replace