|
| 1 | +--- |
| 2 | +sheet: AggregatorSheet |
| 3 | +--- |
| 4 | +# Aggregations like sum, mean, and distinct |
| 5 | + |
| 6 | +Aggregators provide summary statistics for grouped rows. |
| 7 | + |
| 8 | +The current aggregators include: |
| 9 | + |
| 10 | + min smallest value in the group |
| 11 | + max largest value in the group |
| 12 | + avg/mean average value of the group |
| 13 | + mode most frequently appearing value in group |
| 14 | + median median value in the group |
| 15 | + q3/q4/q5/q10 add quantile aggregators to group (e.g. q4 adds p25, p50, p75) |
| 16 | + sum total summation of all numbers in the group |
| 17 | + distinct number of distinct values in the group |
| 18 | + count number of values in the group |
| 19 | + keymax key of the row with the largest value in the group |
| 20 | + list gathers values in column into a list |
| 21 | + stdev standard deviation of values |
| 22 | + |
| 23 | +## View a one-off aggregation of a column |
| 24 | + |
| 25 | +- {help.commands.memo-aggregate} |
| 26 | + |
| 27 | +## Create an aggregator column |
| 28 | + |
| 29 | +Aggregated columns appear in the **Frequency Table** and **Pivot Table** (grouped sheets). Aggregated values will also appear at the bottom of their columns in the source sheet. |
| 30 | + |
| 31 | +- {help.commands.aggregate-col} |
| 32 | + |
| 33 | +Then aggregate the sheet with one of the grouping commands: |
| 34 | + |
| 35 | +- {help.commands.freq-col} |
| 36 | +- {help.commands.pivot} |
| 37 | + |
| 38 | +Aggregators can be viewed and modified on the **Columns Sheet** in the `aggregators` column. |
| 39 | + |
| 40 | +- {help.commands.columns-sheet} |
| 41 | + |
| 42 | +## The Describe Sheet |
| 43 | + |
| 44 | +To get a predefined set of summary statistics for every column in the sheet, use the **Describe Sheet* : |
| 45 | + |
| 46 | +- {help.commands.describe-all} |
| 47 | + |
| 48 | +## Examples |
| 49 | + |
| 50 | +Sample input sheet **sales**: |
| 51 | + |
| 52 | + date color price |
| 53 | + ---------- ----- ----- |
| 54 | + 2024-09-01 R 30 |
| 55 | + 2024-09-02 B 28 |
| 56 | + 2024-09-03 R 100 |
| 57 | + 2024-09-03 B 33 |
| 58 | + 2024-09-03 B 99 |
| 59 | + |
| 60 | +1. Move to the `price` column |
| 61 | +2. Set it to currency: [:keys]$[/key] |
| 62 | +3. Quickly show average price |
| 63 | + - [:keys]z+[/] (`memo-aggregate`) then enter 'avg' |
| 64 | +4. Add an `sum` aggregator column: |
| 65 | + - Press [:keys]+[/] (`aggregate-column`) then enter 'sum' |
| 66 | +5. Move to the date column [:keys]gh[/] |
| 67 | +6. Generate a **Frequency Table** by `date` |
| 68 | + - [:keys]Shift-F[/] (`freq`) |
| 69 | + |
| 70 | + |
| 71 | + date count price_sum |
| 72 | + ---------- ----- --------- |
| 73 | + 2024-09-03 3 232.00 |
| 74 | + 2024-09-01 1 30.00 |
| 75 | + 2024-09-02 1 28.00 |
| 76 | + |
| 77 | +## Creating new aggregator functions |
| 78 | + |
| 79 | +To add a new aggregator to compute the range of the grouped values (max - min), add the following to `.visidatarc`: |
| 80 | + |
| 81 | +[:code]vd.aggregator('range', lambda values: max(values) - min(values), 'range of values')[/] |
| 82 | + |
| 83 | +The `values` parameter is a list of typed values from the column, with the function returning the aggregated value. |
| 84 | +The new aggregator will now be available the next time VisiData is started. |
0 commit comments