Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/CSV-data-manipulation/OCaml/csv-data-manipulation.ocaml
Normal file
19
Task/CSV-data-manipulation/OCaml/csv-data-manipulation.ocaml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
let list_add_last this lst =
|
||||
List.rev (this :: (List.rev lst))
|
||||
|
||||
let () =
|
||||
let csv = Csv.load "data.csv" in
|
||||
let fields, data =
|
||||
(List.hd csv,
|
||||
List.tl csv)
|
||||
in
|
||||
let fields =
|
||||
list_add_last "SUM" fields
|
||||
in
|
||||
let sums =
|
||||
List.map (fun row ->
|
||||
let tot = List.fold_left (fun tot this -> tot + int_of_string this) 0 row in
|
||||
list_add_last (string_of_int tot) row
|
||||
) data
|
||||
in
|
||||
Csv.output_all (Csv.to_channel stdout) (fields :: sums)
|
||||
Loading…
Add table
Add a link
Reference in a new issue