Add documentation for histogram, split-column

This commit is contained in:
Sebastian Jung
2019-11-26 20:47:34 +01:00
committed by Yehuda Katz
parent d6a6e16d21
commit 5406450c42
3 changed files with 245 additions and 1 deletions

172
docs/commands/histogram.md Normal file
View File

@ -0,0 +1,172 @@
# histogram
Creates a new table with a histogram based on the column name passed in.
Syntax: `histogram <column_name> ...args`
### Parameters
* `<column-name>`: name of the column to graph by
* `args`: column name to give the histogram's frequency column
## Examples
Let's say we have this file `random_numers.csv` which contains 50 random numbers.
**Note**: The input doesn't have to be numbers it works on strings too. Try it out.
```shell
> open random_numbers.csv
━━━━┯━━━━━━━━━━━━━━━
# │ random number
────┼───────────────
087
146
239
...
4794
4861
4967
━━━━┷━━━━━━━━━━━━━━━
```
If we now want to see how often the different numbers were generated, we can use the `histogram` function:
```shell
> open random_numbers.csv | histogram "random number"
━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ random number │ frecuency
────┼───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
010 │ *************************
114 │ **************************************************
217 │ *************************
322 │ *************************
424 │ *************************
528 │ *************************
629 │ *************************
731 │ *************************
837 │ *************************
938 │ *************************
1039 │ *************************
1145 │ *************************
1246 │ ***************************************************************************
1349 │ *************************
145 │ *************************
1551 │ ***************************************************************************
1652 │ *************************
1755 │ *************************
1856 │ **************************************************
1960 │ *************************
2061 │ **************************************************
2164 │ *************************
2265 │ *************************
2367 │ **************************************************
2468 │ *************************
2573 │ *************************
2680 │ **************************************************
2782 │ *************************
2886 │ ****************************************************************************************************
2987 │ **************************************************
3088 │ *************************
3189 │ *************************
329 │ *************************
3392 │ *************************
3494 │ *************************
3596 │ *************************
3699 │ *************************
━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
We can also set the name of the second column or sort the table:
```shell
> open random_numbers.csv | histogram "random number" probability
━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ random number │ probability
────┼───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
010 │ *************************
114 │ **************************************************
217 │ *************************
322 │ *************************
424 │ *************************
528 │ *************************
629 │ *************************
731 │ *************************
837 │ *************************
938 │ *************************
1039 │ *************************
1145 │ *************************
1246 │ ***************************************************************************
1349 │ *************************
145 │ *************************
1551 │ ***************************************************************************
1652 │ *************************
1755 │ *************************
1856 │ **************************************************
1960 │ *************************
2061 │ **************************************************
2164 │ *************************
2265 │ *************************
2367 │ **************************************************
2468 │ *************************
2573 │ *************************
2680 │ **************************************************
2782 │ *************************
2886 │ ****************************************************************************************************
2987 │ **************************************************
3088 │ *************************
3189 │ *************************
329 │ *************************
3392 │ *************************
3494 │ *************************
3596 │ *************************
3699 │ *************************
━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
```shell
> open random_numbers.csv | histogram "random number" probability | sort-by probability
━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ random number │ probability
────┼───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
010 │ *************************
117 │ *************************
222 │ *************************
324 │ *************************
428 │ *************************
529 │ *************************
631 │ *************************
737 │ *************************
838 │ *************************
939 │ *************************
1045 │ *************************
1149 │ *************************
125 │ *************************
1352 │ *************************
1455 │ *************************
1560 │ *************************
1664 │ *************************
1765 │ *************************
1868 │ *************************
1973 │ *************************
2082 │ *************************
2188 │ *************************
2289 │ *************************
239 │ *************************
2492 │ *************************
2594 │ *************************
2696 │ *************************
2799 │ *************************
2814 │ **************************************************
2956 │ **************************************************
3061 │ **************************************************
3167 │ **************************************************
3280 │ **************************************************
3387 │ **************************************************
3446 │ ***************************************************************************
3551 │ ***************************************************************************
3686 │ ****************************************************************************************************
━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```

View File

@ -1,5 +1,5 @@
# env
# sort-by
The `sort-by` command sorts the table being displayed in the terminal by a chosen column(s).

View File

@ -0,0 +1,72 @@
# split-column
Split row contents across multiple columns via the separator.
Syntax: `split-column <separator> ...args{flags}`
### Parameters
* `<seperator>`: string that denotes what separates columns
* `args`: column names to give the new columns. If not specified they will be set to `Column1` `Column2` ...
### Flags
--collapse-empty
Removes empty columns
## Examples
If we have file structured like this:
```shell
0.12643678160919541 | 0.6851851851851852 | 0.273972602739726
0.28735632183908044 | 0.09259259259259259 | 0.6986301369863014
0.8045977011494253 | 0.8148148148148148 | 0.7397260273972602
0.28735632183908044 | 0.09259259259259259 | 0.547945205479452
0.6896551724137931 | 0.7037037037037037 | 1.2465753424657535
0.6896551724137931 | 0.8333333333333334 | 0.4657534246575342
0.9080459770114943 | 1.3333333333333333 | 0.4931506849315068
0.9310344827586207 | 1.1296296296296295 | 0.7123287671232876
0.3448275862068966 | 0.018518518518518517 | 0.6575342465753424
1.0459770114942528 | 1.0925925925925926 | 0.6164383561643836
```
We can build a table from it using the `split-column` command
```shell
> open coordinates.txt | lines | split-column " | "
━━━┯━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━
# │ Column1 │ Column2 │ Column3
───┼─────────────────────┼──────────────────────┼────────────────────
0 │ 0.12643678160919541 │ 0.6851851851851852 │ 0.273972602739726
1 │ 0.28735632183908044 │ 0.09259259259259259 │ 0.6986301369863014
2 │ 0.8045977011494253 │ 0.8148148148148148 │ 0.7397260273972602
3 │ 0.28735632183908044 │ 0.09259259259259259 │ 0.547945205479452
4 │ 0.6896551724137931 │ 0.7037037037037037 │ 1.2465753424657535
5 │ 0.6896551724137931 │ 0.8333333333333334 │ 0.4657534246575342
6 │ 0.9080459770114943 │ 1.3333333333333333 │ 0.4931506849315068
7 │ 0.9310344827586207 │ 1.1296296296296295 │ 0.7123287671232876
8 │ 0.3448275862068966 │ 0.018518518518518517 │ 0.6575342465753424
9 │ 1.0459770114942528 │ 1.0925925925925926 │ 0.6164383561643836
━━━┷━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━
```
And give names to the columns
```shell
> open coordinates.txt | lines | split-column " | " x y z
━━━┯━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━
# │ x │ y │ z
───┼─────────────────────┼──────────────────────┼────────────────────
0 │ 0.12643678160919541 │ 0.6851851851851852 │ 0.273972602739726
1 │ 0.28735632183908044 │ 0.09259259259259259 │ 0.6986301369863014
2 │ 0.8045977011494253 │ 0.8148148148148148 │ 0.7397260273972602
3 │ 0.28735632183908044 │ 0.09259259259259259 │ 0.547945205479452
4 │ 0.6896551724137931 │ 0.7037037037037037 │ 1.2465753424657535
5 │ 0.6896551724137931 │ 0.8333333333333334 │ 0.4657534246575342
6 │ 0.9080459770114943 │ 1.3333333333333333 │ 0.4931506849315068
7 │ 0.9310344827586207 │ 1.1296296296296295 │ 0.7123287671232876
8 │ 0.3448275862068966 │ 0.018518518518518517 │ 0.6575342465753424
9 │ 1.0459770114942528 │ 1.0925925925925926 │ 0.6164383561643836
━━━┷━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━
```