Getting Started with Python Expressions
VisiData replaces Excel formulas with Python expressions. Instead of =A2+B2, you write = amount + tax. Column names become variables. The = key creates a new derived column — the equivalent of Excel's formula bar.
Everything starts with = (derived column). Learn how column names map to variables, how to handle column names with spaces, and how to view your expression results. No Python programming background is required — these are one-liners.
This section is designed for accountants, analysts, and spreadsheet users moving from Excel or Google Sheets to VisiData. Each topic shows the Excel formula alongside its VisiData equivalent.
Python Operators Quick Reference
These operators work inside any VisiData expression (=, z|, setcol-expr, etc.):
| Symbol | Meaning | Example | Result |
|---|---|---|---|
= | Start an expression (creates new column) | = salary * 12 | New column with annual salary |
+ | Add or concatenate | = price + tax | Sum of two columns |
- | Subtract or negate | = revenue - cost | Difference |
* | Multiply | = qty * price | Product |
/ | Divide | = total / count | Quotient |
** | Power | = side ** 2 | Area (side squared) |
% | Modulo (remainder) | = id % 10 | Last digit of id |
== | Equal (comparison) | = status == 'done' | True if status is done |
!= | Not equal | = region != 'US' | True if not US |
> | Greater than | = amount > 100 | True if over 100 |
< | Less than | = score < 50 | True if under 50 |
>= | Greater or equal | = age >= 18 | Adult check |
<= | Less or equal | = qty <= 0 | Out of stock |
and | Logical AND | = amount > 0 and status == 'active' | Both must be true |
or | Logical OR | = status == 'urgent' or priority == 1 | Either can be true |
not | Logical NOT | = not approved | True if false |
if / else | Ternary conditional | = 'high' if amount > 500 else 'low' | Conditional value |
in | Membership | = city in ('NYC', 'LA', 'CHI') | True if one of the listed |
// | Integer division | = total // 100 | Divide and drop remainder |
() | Grouping | = (a + b) * c | Override precedence |
Use with any column name as a variable:
= amount + tax # column names as variables
= 'high' if amount > 500 else 'low'
= status == 'done' or status == 'shipped'
= amount > 0 and approved == true
Excel vs VisiData — Core Concept
| Excel | VisiData | Notes |
|---|---|---|
=A2 | = column_name | Reference a column by its name |
=$A$1 | = fixed_value | Constants defined in .visidatarc |
=A2 & " " & B2 | = first + ' ' + last | String concatenation |
#REF! | #ERR | Error when expression fails |
| Drag fill down | i (incremental) | Sequential values |
| Formula bar | = key | Opens expression input |
| Name Box | status bar | Shows current column name |
U | Undo |
Opening a File
vd ~/github/practice-folder/visidata/01-loading/01-employees.csv
This opens a sheet where:
- Each row = one employee record
- Each column header = variable name usable in expressions
- Column names are case-sensitive
Creating a Derived Column with =
Press = and type a Python expression. Column names are available as variables:
vd ~/github/practice-folder/visidata/01-loading/01-employees.csv
# Excel: =salary * 12
# VisiData:
=
# Enter: salary * 12
# Prompts for column name: annual_salary
# Excel: =first_name & " " & last_name
# VisiData:
=
# Enter: first_name + ' ' + last_name
# Prompts for column name: full_name
# Excel: =IF(salary>70000, "Senior", "Junior")
# VisiData:
=
# Enter: 'Senior' if salary > 70000 else 'Junior'
# Prompts for column name: tier
Column Names with Spaces
If a column name contains spaces, use row['column name']:
# Excel column header: "First Name"
# VisiData:
= row['First Name'] + ' ' + row['Last Name']
# Or: rename the column first (^ key) to remove spaces
Viewing Expression Results
The derived column appears immediately to the right of the cursor column. It is computed on demand — it does not modify the source file.
# Verify the expression worked:
# 1. Look at the new column — does it show expected values?
# 2. Check the status bar for any #ERR cells
# 3. Press Ctrl+G to see column info
Column Types Matter
Before using columns in math expressions, cast them to numeric types:
vd ~/github/practice-folder/visidata/01-loading/01-employees.csv
# Cast 'salary' to float (like telling Excel the cell is a number)
# Move to 'salary' column → press %
%
# Cast 'start_date' to date
# Move to 'start_date' column → press @
@
# Cast 'department_id' to integer
# Move to 'department_id' column → press #
#
Type casting equivalents:
| Excel | VisiData Key | Type |
|---|---|---|
| Format as Number | # | int |
| Format as Decimal | % | float |
| Format as Currency | $ | currency |
| Format as Date | @ | date |
| Format as Text | ~ | str |
Setting Constants in .visidatarc
In Excel, you use a fixed cell reference like $B$1 for constants. In VisiData, define them in ~/.visidatarc:
# ~/.visidatarc
TAX_RATE = 0.07
GST_RATE = 0.09
FISCAL_YEAR = 2025
# Then use in expressions:
# = salary * TAX_RATE
# = amount * (1 + GST_RATE)
Bulk Set with g=
g= sets the current column for all selected rows to an expression result — like filling a formula down in Excel for selected rows only:
# Excel: select cells → fill down with Ctrl+D
# VisiData:
gs # select all rows
g=
# Enter: 'APAC'
# Sets the current column to 'APAC' for every selected row
Error Handling
| Excel | VisiData |
|---|---|
#REF! | #ERR |
=IFERROR(A/B, 0) | = (a / b) if b != 0 else 0 |
#DIV/0! | #ERR when dividing by zero |
# Safe division:
=
# Enter: (revenue / units) if units != 0 else 0
Hands-On Practice
vd ~/github/practice-folder/visidata/01-loading/01-employees.csv
# 1. Cast salary to float: move to 'salary' → press %
# 2. Create annual salary:
=
# Enter: salary * 12
# Name: annual_salary
# 3. Create salary tier:
=
# Enter: 'high' if salary > 70000 else 'mid' if salary > 50000 else 'low'
# Name: tier
# 4. Create full name (if first_name and last_name columns exist):
=
# Enter: first_name + ' ' + last_name
# Name: full_name
# 5. Verify: scroll right to see new columns
# 6. Press Ctrl+S → save as: /tmp/employees_enriched.csv