nushell/docs/commands/histogram.md
Joseph T. Lyons 9fb6f5cd09
Change f/full flag to l/long for ls and ps commands (#2283)
* Change `f`/`full` flag to `l`/`long` for `ls` and `ps` commands

* Fix a few more `--full` instances
2020-08-02 06:30:45 +12:00

8 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 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.

> open random_numbers.csv
────┬────────────────
 #  │ random numbers
────┼────────────────
  01
  12
  22
...
 475
 485
 491
────┴────────────────

If we now want to see how often the different numbers were generated, we can use the histogram function:

> open random_numbers.csv | histogram "random numbers"
───┬────────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
 # │ random numbers │ count │ frequency
───┼────────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
 001 │ ******
 1115 │ ****************************************************************************************************
 2210 │ ******************************************************************
 337 │ **********************************************
 449 │ ************************************************************
 558 │ *****************************************************
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────

We can also set the name of the second column or sort the table:

> open random_numbers.csv | histogram "random numbers" probability
───┬────────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
 # │ random numbers │ count │ probability
───┼────────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
 001 │ ******
 1115 │ ****************************************************************************************************
 2210 │ ******************************************************************
 337 │ **********************************************
 449 │ ************************************************************
 558 │ *****************************************************
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────

> open random_numbers.csv | histogram "random numbers" probability | sort-by probability
───┬────────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
 # │ random numbers │ count │ probability
───┼────────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
 001 │ ******
 137 │ **********************************************
 258 │ *****************************************************
 349 │ ************************************************************
 4210 │ ******************************************************************
 5115 │ ****************************************************************************************************
───┴────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────

Of course, histogram operations are not restricted to just analyzing numbers in files, you can also analyze your directories

> ls -la | histogram type | sort-by count
───┬─────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
 # │ type    │ count │ frequency
───┼─────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
 0 │ Symlink │     8 │ *****************
 1 │ File    │     9 │ ********************
 2 │ Dir     │    45 │ ****************************************************************************************************
───┴─────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────