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