mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 09:48:28 +02:00
Update histogram examples
This commit is contained in:
committed by
Andrés N. Robalino
parent
d1d98a897a
commit
8f00713ad2
@ -20,13 +20,13 @@ Let's say we have this file `random_numers.csv` which contains 50 random numbers
|
||||
────┬────────────────
|
||||
# │ random numbers
|
||||
────┼────────────────
|
||||
0 │ 1
|
||||
0 │ 5
|
||||
1 │ 2
|
||||
2 │ 2
|
||||
2 │ 0
|
||||
...
|
||||
47 │ 5
|
||||
48 │ 5
|
||||
49 │ 1
|
||||
47 │ 1
|
||||
48 │ 1
|
||||
49 │ 2
|
||||
────┴────────────────
|
||||
```
|
||||
|
||||
@ -34,59 +34,59 @@ If we now want to see how often the different numbers were generated, we can use
|
||||
|
||||
```shell
|
||||
> 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 │ *****************************************************
|
||||
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
───┬────────────────┬─────────────┬────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# │ random numbers │ occurrences │ percentage │ frequency
|
||||
───┼────────────────┼─────────────┼────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
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% │ ***********************************************************************
|
||||
───┴────────────────┴─────────────┴────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
```
|
||||
|
||||
We can also set the name of the second column or sort the table:
|
||||
|
||||
```shell
|
||||
> 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 │ *****************************************************
|
||||
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
───┬────────────────┬─────────────┬────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# │ random numbers │ occurrences │ percentage │ probability
|
||||
───┼────────────────┼─────────────┼────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
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% │ ***********************************************************************
|
||||
───┴────────────────┴─────────────┴────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
```
|
||||
|
||||
```shell
|
||||
> 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 │ ****************************************************************************************************
|
||||
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
───┬────────────────┬─────────────┬────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# │ random numbers │ occurrences │ percentage │ probability
|
||||
───┼────────────────┼─────────────┼────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
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% │ ****************************************************************************************************
|
||||
───┴────────────────┴─────────────┴────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
```
|
||||
|
||||
Of course, histogram operations are not restricted to just analyzing numbers in files, you can also analyze your directories
|
||||
|
||||
```shell
|
||||
> ls -la | histogram type | sort-by count
|
||||
───┬─────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# │ type │ count │ frequency
|
||||
───┼─────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
0 │ Symlink │ 8 │ *****************
|
||||
1 │ File │ 9 │ ********************
|
||||
2 │ Dir │ 45 │ ****************************************************************************************************
|
||||
───┴─────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
> ls -la | histogram type | sort-by occurrences
|
||||
───┬─────────┬─────────────┬────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# │ type │ occurrences │ percentage │ frequency
|
||||
───┼─────────┼─────────────┼────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
0 │ Dir │ 5 │ 4.76% │ ****
|
||||
1 │ Symlink │ 28 │ 26.67% │ **************************
|
||||
2 │ File │ 105 │ 100.00% │ ****************************************************************************************************
|
||||
───┴─────────┴─────────────┴────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
```
|
||||
|
Reference in New Issue
Block a user