mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
5ca9e12b7f
* 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
6.1 KiB
6.1 KiB
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 byargs
: 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.
> 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:
> 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:
> open random_numbers2.csv | histogram "random numbers" probability
━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ random numbers │ probability
───┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
0 │ 0 │ ****************************************************************************************************
1 │ 1 │ ******************************
2 │ 2 │ *************************************************************
3 │ 3 │ *********************************************************************
4 │ 4 │ *****************************************************
5 │ 5 │ *********************************************************************
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> 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 │ ****************************************************************************************************
━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━