2019-11-26 19:47:34 +00:00
|
|
|
# histogram
|
|
|
|
|
|
|
|
Creates a new table with a histogram based on the column name passed in.
|
|
|
|
|
|
|
|
Syntax: `histogram <column_name> ...args`
|
|
|
|
|
2020-06-23 18:21:47 +00:00
|
|
|
## Parameters
|
2019-11-26 19:47:34 +00:00
|
|
|
|
|
|
|
* `<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
|
2020-05-20 06:02:36 +00:00
|
|
|
────┬────────────────
|
2020-03-13 17:23:41 +00:00
|
|
|
# │ random numbers
|
2019-11-28 18:32:31 +00:00
|
|
|
────┼────────────────
|
2020-05-20 06:02:36 +00:00
|
|
|
0 │ 1
|
|
|
|
1 │ 2
|
|
|
|
2 │ 2
|
2020-06-23 18:21:47 +00:00
|
|
|
...
|
2020-05-20 06:02:36 +00:00
|
|
|
47 │ 5
|
|
|
|
48 │ 5
|
|
|
|
49 │ 1
|
|
|
|
────┴────────────────
|
2019-11-26 19:47:34 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
If we now want to see how often the different numbers were generated, we can use the `histogram` function:
|
|
|
|
|
|
|
|
```shell
|
2020-05-20 06:02:36 +00:00
|
|
|
> open random_numbers.csv | histogram "random numbers"
|
|
|
|
───┬────────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
# │ random numbers │ count │ frequency
|
|
|
|
───┼────────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
0 │ 0 │ 1 │ ******
|
|
|
|
1 │ 1 │ 15 │ ****************************************************************************************************
|
|
|
|
2 │ 2 │ 10 │ ******************************************************************
|
|
|
|
3 │ 3 │ 7 │ **********************************************
|
|
|
|
4 │ 4 │ 9 │ ************************************************************
|
|
|
|
5 │ 5 │ 8 │ *****************************************************
|
|
|
|
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
2019-11-26 19:47:34 +00:00
|
|
|
```
|
|
|
|
|
2020-03-13 17:23:41 +00:00
|
|
|
We can also set the name of the second column or sort the table:
|
2019-11-26 19:47:34 +00:00
|
|
|
|
|
|
|
```shell
|
2020-05-20 06:02:36 +00:00
|
|
|
> open random_numbers.csv | histogram "random numbers" probability
|
|
|
|
───┬────────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
# │ random numbers │ count │ probability
|
|
|
|
───┼────────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
0 │ 0 │ 1 │ ******
|
|
|
|
1 │ 1 │ 15 │ ****************************************************************************************************
|
|
|
|
2 │ 2 │ 10 │ ******************************************************************
|
|
|
|
3 │ 3 │ 7 │ **********************************************
|
|
|
|
4 │ 4 │ 9 │ ************************************************************
|
|
|
|
5 │ 5 │ 8 │ *****************************************************
|
|
|
|
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
2019-11-28 18:32:31 +00:00
|
|
|
|
2019-11-26 19:47:34 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
```shell
|
2020-05-20 06:02:36 +00:00
|
|
|
> open random_numbers.csv | histogram "random numbers" probability | sort-by probability
|
|
|
|
───┬────────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
# │ random numbers │ count │ probability
|
|
|
|
───┼────────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
0 │ 0 │ 1 │ ******
|
|
|
|
1 │ 3 │ 7 │ **********************************************
|
|
|
|
2 │ 5 │ 8 │ *****************************************************
|
|
|
|
3 │ 4 │ 9 │ ************************************************************
|
|
|
|
4 │ 2 │ 10 │ ******************************************************************
|
|
|
|
5 │ 1 │ 15 │ ****************************************************************************************************
|
|
|
|
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
Of course, histogram operations are not restricted to just analyzing numbers in files, you can also analyze your directories
|
|
|
|
|
|
|
|
```shell
|
2020-08-01 18:30:45 +00:00
|
|
|
> ls -la | histogram type | sort-by count
|
2020-05-20 06:02:36 +00:00
|
|
|
───┬─────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
# │ type │ count │ frequency
|
|
|
|
───┼─────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
0 │ Symlink │ 8 │ *****************
|
|
|
|
1 │ File │ 9 │ ********************
|
|
|
|
2 │ Dir │ 45 │ ****************************************************************************************************
|
|
|
|
───┴─────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
```
|