Added a count column on the histogram command (#1853)

* Adding iniitial draft for the addition of the count column on the histogram command

* Update histogram documentation

* Add count column test to histogram command

* Fix error in histogram documentation
This commit is contained in:
Joseph T. Lyons
2020-05-20 02:02:36 -04:00
committed by GitHub
parent b22db39775
commit 3239e5055c
3 changed files with 103 additions and 44 deletions

View File

@ -17,64 +17,76 @@ Let's say we have this file `random_numers.csv` which contains 50 random numbers
```shell
> open random_numbers.csv
open random_numbers2.csv
━━━━┯━━━━━━━━━━━━━━━━
────┬────────────────
# │ random numbers
────┼────────────────
00
15
25
...
470
482
494
━━━━┷━━━━━━━━━━━━━━━━
0 1
1 2
2 2
...
47 5
48 5
49 1
────┴────────────────
```
If we now want to see how often the different numbers were generated, we can use the `histogram` function:
```shell
> open random_numbers2.csv | histogram "random numbers"
━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ random numbers │ frequency
───┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
00****************************************************************************************************
11 │ ******************************
22 │ *************************************************************
33*********************************************************************
44 │ *****************************************************
55*********************************************************************
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> open random_numbers.csv | histogram "random numbers"
───┬────────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
# │ random numbers │ count │ frequency
───┼────────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
00 1******
11 15 │ ****************************************************************************************************
22 10 │ ******************************************************************
33 7**********************************************
44 9 │ ************************************************************
55 8*****************************************************
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
```
We can also set the name of the second column or sort the table:
```shell
> open random_numbers2.csv | histogram "random numbers" probability
━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ random numbers │ probability
───┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
00****************************************************************************************************
11 │ ******************************
22 │ *************************************************************
33*********************************************************************
44 │ *****************************************************
55*********************************************************************
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> open random_numbers.csv | histogram "random numbers" probability
───┬────────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
# │ random numbers │ count │ probability
───┼────────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
00 1******
11 15 │ ****************************************************************************************************
22 10 │ ******************************************************************
33 7**********************************************
44 9 │ ************************************************************
55 8*****************************************************
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
```
```shell
> open random_numbers2.csv | histogram "random numbers" probability | sort-by probability
━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ random numbers │ probability
───┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
01******************************
14*****************************************************
22*************************************************************
33*********************************************************************
45*********************************************************************
50 │ ****************************************************************************************************
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> open random_numbers.csv | histogram "random numbers" probability | sort-by probability
───┬────────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
# │ random numbers │ count │ probability
───┼────────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
00 1******
13 7**********************************************
25 8*****************************************************
34 9************************************************************
42 10******************************************************************
51 15 ****************************************************************************************************
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
```
```
Of course, histogram operations are not restricted to just analyzing numbers in files, you can also analyze your directories
```shell
> ls -fa | histogram type | sort-by count
───┬─────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
# │ type │ count │ frequency
───┼─────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
0 │ Symlink │ 8 │ *****************
1 │ File │ 9 │ ********************
2 │ Dir │ 45 │ ****************************************************************************************************
───┴─────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
```