nushell/docs/commands/histogram.md
2019-12-02 11:02:59 -08:00

80 lines
No EOL
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
────┼────────────────
00
15
25
...
470
482
494
━━━━┷━━━━━━━━━━━━━━━━
```
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 │ *********************************************************************
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
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 │ *********************************************************************
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
```shell
> open random_numbers2.csv | histogram "random numbers" probability | sort-by probability
━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ random numbers │ probability
───┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
01 │ ******************************
14 │ *****************************************************
22 │ *************************************************************
33 │ *********************************************************************
45 │ *********************************************************************
50 │ ****************************************************************************************************
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```