nushell/docs/commands/histogram.md
Waldir Pimenta 5ca9e12b7f
Fix whitespace and typos (#1481)
* Remove EOL whitespace in files other than docs

* Break paragraphs into lines

See http://rhodesmill.org/brandon/2012/one-sentence-per-line/ for the rationale

* Fix various typos

* Remove EOL whitespace in docs/commands/*.md
2020-03-14 06:23:41 +13:00

80 lines
6.1 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 │ ****************************************************************************************************
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```