From f9fbb0eb3c3a4482afd5eaaebb90c6a743fa6aaf Mon Sep 17 00:00:00 2001 From: "notryanb@gmail.com" Date: Wed, 16 Oct 2019 20:40:19 -0400 Subject: [PATCH] add docs for average and give more specific examples for sum --- docs/commands/average.md | 42 ++++++++++++++++++++++++++++++++++++++++ docs/commands/sum.md | 42 ++++++++++++++++++++++++---------------- 2 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 docs/commands/average.md diff --git a/docs/commands/average.md b/docs/commands/average.md new file mode 100644 index 0000000000..701ad6091b --- /dev/null +++ b/docs/commands/average.md @@ -0,0 +1,42 @@ +# average This command allows you to calculate the average of values in a column. ## Examples +To get the average of the file sizes in a directory, simply pipe the size column from the ls command to the sum command. + +```shell +> ls | get size | average +━━━━━━━━━ + +━━━━━━━━━ +2282.727272727273 +━━━━━━━━━ +``` + +```shell +> pwd | split-row / | size | get chars | average +━━━━━━━━━ + +━━━━━━━━━ +5.250000000000000 +━━━━━━━━━ +``` + +Note that average only works for integer and byte values at the moment, and if the shell doesn't recognize the values in a column as one of those types, it will return an error. +One way to solve this is to convert each row to an integer and then pipe the result to `average` + +```shell +> open tests/fixtures/formats/caco3_plastics.csv | get tariff_item | average +error: Unrecognized type in stream: Primitive(String("2509000000")) +- shell:1:0 +1 | open tests/fixtures/formats/caco3_plastics.csv | get tariff_item | average + | ^^^^ source +``` + +```shell +> open tests/fixtures/formats/caco3_plastics.csv | get tariff_item | str --to-int | average +━━━━━━━━━━━━━━━━━━━ + +─────────────────── + 3239404444.000000 +━━━━━━━━━━━━━━━━━━━ +``` + + diff --git a/docs/commands/sum.md b/docs/commands/sum.md index f5c59848dd..f20dcb5f37 100644 --- a/docs/commands/sum.md +++ b/docs/commands/sum.md @@ -1,9 +1,4 @@ -# sum - -This command allows you to calculate the sum of values in a column. - -## Examples - +# sum This command allows you to calculate the sum of values in a column. ## Examples To get the sum of the file sizes in a directory, simply pipe the size column from the ls command to the sum command. ```shell @@ -15,21 +10,34 @@ To get the sum of the file sizes in a directory, simply pipe the size column fro ━━━━━━━━━ ``` +To get the sum of the characters in your present working directory. +```shell +> pwd | split-row / | size | get chars | sum +━━━━━━━━━ + +━━━━━━━━━ +21 +━━━━━━━━━ +``` + + + Note that sum only works for integer and byte values at the moment, and if the shell doesn't recognize the values in a column as one of those types, it will return an error. +One way to solve this is to convert each row to an integer and then pipe the result to `sum` ```shell -> open example.csv -━━━┯━━━━━━━━━┯━━━━━━━━┯━━━━━━━━━━ - # │ fruit │ amount │ quality -───┼─────────┼────────┼────────── - 0 │ apples │ 1 │ fresh - 1 │ bananas │ 2 │ old - 2 │ oranges │ 7 │ fresh - 3 │ kiwis │ 25 │ rotten -━━━┷━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━ +> open tests/fixtures/formats/caco3_plastics.csv | get tariff_item | average +error: Unrecognized type in stream: Primitive(String("2509000000")) +- shell:1:0 +1 | open tests/fixtures/formats/caco3_plastics.csv | get tariff_item | sum + | ^^^^ source ``` ```shell -> open example.csv | get amount | sum -error: Unrecognized type in stream: Primitive(String("1")) +> open tests/fixtures/formats/caco3_plastics.csv | get tariff_item | str --to-int | sum +━━━━━━━━━━━━━ + +───────────── + 29154639996 +━━━━━━━━━━━━━ ```