Skip to content

Commit 381e202

Browse files
committed
Clean up the FrequencyTable guide
- remove examples, as it is already quite long - reword many sections to simplify the language - trim and condense explanatory text
1 parent 8ebfc01 commit 381e202

File tree

1 file changed

+59
-76
lines changed

1 file changed

+59
-76
lines changed

visidata/guides/FrequencyTable.md

+59-76
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,100 @@
11
# Frequency Tables are how you GROUP BY
22

3-
## About Frequency Tables
4-
5-
A VisiData frequency table groups data into bins using one or more columns, and creates basic summary aggregates of the data. The default aggregates are as follows. However, if user-defined aggregate columns are present, they will also be included.
6-
7-
- count - (the count of rows in each group)
8-
- percent - (the percentage of the total rows in each group)
9-
- histogram - (a visual representation of the percentage)
10-
11-
Here's a tiny dataset of hat purchases. Each purchase may include multiple hats.
12-
13-
```
14-
+------------+-------+----------+-------+-------+
15-
| date | color | hatCount | price | total |
16-
+------------+-------+----------+-------+-------+
17-
| 2024-09-01 | Red | 1 | 30 | 30 |
18-
| 2024-09-02 | Blue | 1 | 28 | 28 |
19-
| 2024-09-02 | Green | 2 | 32 | 64 |
20-
| 2024-09-03 | Red | 4 | 25 | 100 |
21-
| 2024-09-03 | Blue | 1 | 33 | 33 |
22-
| 2024-09-03 | Blue | 3 | 33 | 99 |
23-
+------------+-------+----------+-------+-------+
24-
```
25-
26-
A Frequency Table for the `color` column looks like:
27-
28-
```
29-
+-------+-------+---------+----------------------------------------+
30-
| color | count | percent | histogram |
31-
+-------+-------+---------+----------------------------------------+
32-
| Blue | 3 | 50 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ |
33-
| Red | 2 | 33.33 | ■■■■■■■■■■■■■■■■■■■■■■■■■ |
34-
| Green | 1 | 16.67 | ■■■■■■■■■■■■ |
35-
+-------+-------+---------+----------------------------------------+
36-
```
37-
38-
Given data like this, use a frequency table to answer questions like:
39-
40-
- How many purchases (rows) per day?
41-
- What unique colors were sold?
42-
- How many purchases (rows) per day and color?
43-
- What color generated the most in total sales?
44-
- What is the first purchase (row) for each day?
3+
- Group data into bins using one or more columns.
4+
- Count the number of items in each group.
5+
- Also perform custom aggregations for each group.
456

46-
## Group by a single column
7+
- Similar to SQL:
478

48-
To group by date, navigate to the `date` column and press {help.commands.freq_col}
9+
SELECT column_name, COUNT(*)
10+
FROM sheet_name
11+
GROUP BY column_name
12+
ORDER BY COUNT(*) DESC
4913

50-
Note that in addition to getting the counts, the frequency table also provides a list of unique items in the selected column.
14+
## Group by a single column
5115

52-
For example, navigating to the `color` column and pressing [:keys]Shift+F[/] is a quick way to see the unique colors.
16+
1. Navigate to the target column
17+
- {help.commands.freq_col}
5318

5419
## Group by multiple columns
5520

56-
To group by multiple columns, the grouping columns must be set as key columns.
57-
21+
1. Set one or more columns as key columns:
5822
- use {help.commands.key_col}
5923

60-
In this example, date and color could be set as key columns.
24+
2. group by the key columns to create a frequency table:
25+
- {help.commands.freq_keys}
6126

62-
After setting one or more key columns, group by the key columns to create a frequency table:
27+
## Aggregators
6328

64-
- {help.commands.freq_keys}
29+
Add aggregators to one or or more columns BEFORE creating a frequency table.
30+
- Aggregators include min, max, sum, distinct count, and list.
6531

66-
This table can answer how many invoices were created per date and color.
32+
1. Navigate to a column.
33+
2. Add aggregators (like min, max, sum, list, and distinct count).
34+
- {help.commands.aggregate-col}
6735

68-
## User-defined aggregates
36+
3. Add more aggregators to the same or different columns.
37+
4. Generate the Frequency Table. [:keys]Shift+F[/] or [:keys]gShift+F[/]
6938

70-
Note that in the examples above, only the row count was aggregated. Frequently, you want to add additional aggregations (like min, max, sum and/or average). These aggregations must be added before generating the frequency table, and they will show up next to built-in aggregations.
39+
## Explore the frequency data
7140

72-
In this example, you can add a `sum` aggregation to the `total` column, and then group by the `color` column:
41+
Dive into a group to see the underlying row(s) using the **Frequency Table**:
7342

74-
- Navigate to the `total` column: [:keys]gShift+L[/]
75-
- Add a `sum` aggregate [:keys]+[/] then enter [:keys]sum[/]
76-
- Navigate to the `color` column
77-
- Create the frequency table by pressing [:keys]Shift+F[/]
43+
1. Navigate to the target row.
44+
- {help.commands.open_row}
7845

79-
## Quick Summary
46+
Dive into multiple groups:
8047

81-
To quickly compare the frequency and aggregates of selected rows compared to the total dataset, use
48+
- Select multiple rows, for example with [:keys]t[/] (stoggle-row)
49+
- {help.commands.dive_selected}
8250

83-
- {help.commands.freq_summary}
51+
Return to the frequency table:
52+
- {help.commands.jump_prev}
8453

85-
## Exploring the data
54+
Select the first row of each group, and then return to the source data. For example, identify a sample from each each group:
8655

87-
From the `FrequencySheet`, you can explore the underlying data for a single group using the following commands:
56+
- (`select-first`) - select first source row in each bin
57+
- {help.commands.jump_prev}
8858

89-
- {help.commands.open_row}
59+
## Find Unique Values
9060

91-
To explore multiple rows within the frequency table, select multiple rows, for example with [:keys]t[/] (stoggle-row)
61+
The bins of a frequeny table are the unique items.
62+
- The total unique count appears in the bottom right of the window, for example "14 bins".
9263

93-
- {help.commands.dive_selected}
64+
Copy the unique item list to a new sheet:
9465

95-
In addition to seeing all of the individual rows, sometimes it is helpful to just see the first item from each group. Perhaps you want to see when something first occurred, or to see a representative sample of each group.
66+
1. Generate a frequency table (one or more columns).
67+
2. Hide unwanted columns. [:keys]-[/] or [:keys]Shift+C[/]
68+
3. Copy unique values to a new sheet
69+
- {help.commands.freeze-sheet}
9670

97-
- {help.commands.select_first}
71+
## Count only selected rows
9872

99-
The rows are selected in the original sheet, so you must leave the frequency table and return to to the source sheet. One way is with:
100-
- {help.commands.jump_prev}
73+
Create an ad-hoc frequeny table that compares the selected rows in the current columns to all rows:
10174

75+
- {help.commands.freq_summary}
76+
77+
The frequency summary can use aggregators as well.
10278

103-
## Sorting the data
79+
## Sort the table
10480

105-
Like with other sheets, sort Frequency Table data by navigating to the desired column and using the sort keys:
81+
Navigate to the target column and sort:
10682

10783
- {help.commands.sort_asc}
10884
- {help.commands.sort_desc}
10985

11086
## Using Split Panes with Frequency Tables
11187

112-
There are a few functions that combine Split Panes (see the `SplitplanesGuide`) and Frequency Tables.
88+
Open a split [:keys]Shift+Z[/], and create a Frequency Table [:keys]Shift+F[/].
89+
- The table will automatically open in the other split.
90+
91+
1. Open a Frequency Table
92+
2. open a new split, when you explore the group(s) with [:keys]Enter[/] or [:keys]gEnter[/], the detail view will open in the other pane.
93+
94+
See alo the `SplitplanesGuide`.
11395

114-
If you have an open split [:keys]Shift+Z[/], and create a Frequency Table, it will automatically open in the other split.
96+
## Table Options
11597

116-
Similarly, if you are in a Frequency Table and open a new split, when you explore the group(s) with [:keys]Enter[/] or [:keys]gEnter[/], the detail view will open in the other pane.
98+
- {help.options.disp_histogram}
99+
- {help.options.disp_histlen}
117100

0 commit comments

Comments
 (0)