mirror of
https://github.com/nushell/nushell.git
synced 2024-12-27 01:19:25 +01:00
80 lines
6.2 KiB
Markdown
80 lines
6.2 KiB
Markdown
# 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
|
|
open random_numbers2.csv
|
|
━━━━┯━━━━━━━━━━━━━━━━
|
|
# │ random numbers
|
|
────┼────────────────
|
|
0 │ 0
|
|
1 │ 5
|
|
2 │ 5
|
|
...
|
|
47 │ 0
|
|
48 │ 2
|
|
49 │ 4
|
|
━━━━┷━━━━━━━━━━━━━━━━
|
|
```
|
|
|
|
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
|
|
───┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
0 │ 0 │ ****************************************************************************************************
|
|
1 │ 1 │ ******************************
|
|
2 │ 2 │ *************************************************************
|
|
3 │ 3 │ *********************************************************************
|
|
4 │ 4 │ *****************************************************
|
|
5 │ 5 │ *********************************************************************
|
|
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
```
|
|
|
|
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
|
|
───┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
0 │ 0 │ ****************************************************************************************************
|
|
1 │ 1 │ ******************************
|
|
2 │ 2 │ *************************************************************
|
|
3 │ 3 │ *********************************************************************
|
|
4 │ 4 │ *****************************************************
|
|
5 │ 5 │ *********************************************************************
|
|
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
|
|
```
|
|
|
|
```shell
|
|
> open random_numbers2.csv | histogram "random numbers" probability | sort-by probability
|
|
━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
# │ random numbers │ probability
|
|
───┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
0 │ 1 │ ******************************
|
|
1 │ 4 │ *****************************************************
|
|
2 │ 2 │ *************************************************************
|
|
3 │ 3 │ *********************************************************************
|
|
4 │ 5 │ *********************************************************************
|
|
5 │ 0 │ ****************************************************************************************************
|
|
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
|
|
``` |