Rows
How to perform operations on a subset of rows
Many commands can be finetuned to operate on rows which are 'selected'.
How to specify the subset of rows which are selected
| Command(s) | Operation |
|---|---|
s t u |
select/toggle/unselect current row |
gs gt gu |
select/toggle/unselect all rows |
| \ regex |
select/unselect rows matching regex in current column |
g| g\ regex |
select/unselect rows matching regex in any visible column |
z| z\ expr |
select/unselect rows matching Python expr in any visible column |
, |
select rows matching current cell in current column |
g, |
select rows matching entire current row in all visible columns |
An example usage follows.
How to filter rows
Press
sorton the rows to be filtered.Press
a.
gdto delete the selected rows.or
b.
"to open a duplicate sheet which has references to the selected rows. Edits performed within the duplicate sheet will also propagate to the source sheet.or
c.
g"to open a duplicate sheet which has references to all rows, and keeping the selected rows selected. The selection can be modified on the parent sheet and the new sheet independently, but any changes will not be reflected on both sheets.or
d.
z"to open a copy of the sheet which has copies of the selected rows. Any changes will not affect the source sheet.or
d.
gz"to open a copy of the sheet which has copies of all rows. Any changes will be reflected on the source sheet
The following example uses the file sample.tsv.
Question On which days have we sold less than 10 Binders?
- Scroll to the
Unitscolumn. Set the type of theUnitscolumn by pressing#(int). - Type
z|followed byItem == 'Binder' and Units < 10to select all of the rows where theItemis Binder and the number ofUnitsis less than 10. - Press
"to open a duplicate sheet with only those selected rows.
How to filter a random subset of rows
- Type
Spacerandom-rowsfollowed by the number of rows you wish included in your random population sample.
How to select rows where the current column is not null or empty?
'Null' cells, by default, are cells which contain None. This can be changed with options.null_value. Null cells can be set with zd (set current cell to None) or gzd (set selected rows in current column to None). Null cells are distinguished with a yellow ∅' symbol on the right hand corner. They are distinct from empty cells (which are '' in columns of string type.)
- Type
|followed by . to select all rows without empty or null cells in the current column.
How to select rows where the current column is null?
There are several different options:
z,matches by typed value while,matches by display value. Move to an empty orNonecell in the column of interest and press,to select all empty andNonecells in that column. Typez,on aNonecell to select all rows that containNonein that column. Typez.on an empty cell to select all rows that have an empty cell in that column.- Open a DescribeSheet for the current sheet with
Shift+I. Move to the nulls column, and then move to the row which references the source column of interest. Typezsto select all null rows for that column. z|is a command which allows selection by provided Python expression criteria (using column names as variables). For non-numerical columnsz|followed by not ColumnName, will select all empty cells andNonecells for that column. For numerical columns it will also select cells with0.- A typed value of Python None is always a
TypedWrapper, which allows sorting, etc., on columns with None values. For this reasonz|ColumnName is None will not work, thoughtz|ColumnName.val is None will work. This is not a recommended approach, though at the moment, it is available.
How to move, copy and remove rows
| Command(s) | Operation |
|---|---|
J K |
move cursor row down/up |
gJ gK |
move cursor row all the way to the bottom/top of sheet |
How to copy and paste a single row
- Press
yto copy the row to the clipboard. - Move the cursor to the desired location.
- Press
p/Shift+Pto paste the row after/before current row.
How to copy and paste multiple rows
- Press
s/ton those rows to select them. - Press
gyto copy all selected rows to the clipboard. - Move the cursor to the desired location.
- Press
p/Shift+Pto paste those rows after/before current row.
Note
VisiData has a universal paste mechanism: it creates new rows on the target sheet and then fills them with values from the copied rows from the previous sheet.
This value-filling happens positionally, so if columns are missing or in a different order, the values will be in different columns,
How to sort rows
| Command(s) | Operation |
|---|---|
[ ] |
sorts ascending/descending by current column; replace any existing sort criteria |
g[ g] |
sorts ascending/descending by all key columns; replace any existing sort criteria |
z[ z] |
sorts ascending/descending by current column; add to existing sort criteria |
gz[ gz] |
sorts ascending/descending by all key column; add to existing sort criteria |
How to sort a numerical column from highest number to lowest:
- Set the type of the column being sorted by pressing
#(int) or%(float). - Press
[to sort the column from highest to lowest.
How to sort a date column in chronological order:
- Set the type of the column being sorted by pressing
@(date). - Press
]to sort the column chronologically.
How to sort based on multiple columns
- Press
!on those columns to designate them as key columns. - Press
g[org]to sort.
or
- Sort the first column with
[or]. - Sort the next column with
z[orz]to add sorting to the existing criteria.
How to increase row height
Press v on any TableSheet to toggle multi-line rows. This dynamically lengthens rows so that the full content of the column is visible.
Multi-line rows have some limitations; they can't be paged, for instance. The full contents of a cell can be viewed or edited in an external program like emacs or less:
- Press
eon a cell to enter Editing mode. Then scroll left and right to explore its contents. - Press
Ctrl+Owhile in editing mode, to open the contents of the current cell in an external $EDITOR.
TextSheet-specific options TextSheets are used for loading .txt files in VisiData. They are also the default loaders used for un-identified sources. They are notable for having a single column which has the name "text".
TextSheets have a bonus option wrap which will wrap the text into multiple rows, so that it fits the window width.
- On TextSheet, press
Shift+Oto open its OptionsSheet. PressEnteron thewrapoption, to set it to True. Pressqto return to your TextSheet. Reload it withCtrl+R. Note that reload undoes an previous modifications you may have made to the TextSheet. - On the commandline, the option
--wrapwill set thewrapoption to True for all TextSheets in that session. - In your
~.visidatarc,options.wrap = Truewill set thewrapoption to True for all TextSheets in every session.
