Skip to main content

Column Naming

Column names are variables in Python expressions. Naming your columns well before writing derived column expressions is the difference between = salary * 0.10 and = row['Annual Salary'] * 0.10.

Learning Focus

Rename columns with ^, use cell values as names with z^, and bulk-rename with g^. Always remove spaces from column names before writing Python expressions.

Sample Data Used in This Lesson

cat > ~/github/practice-folder/visidata/01-loading/01-employees.csv << 'EOF'
emp_id,name,department,region,salary,hire_date
E001,Alice,Engineering,SG,85000,2020-03-15
E002,Bob,Marketing,KL,70000,2019-11-01
E003,Charlie,Engineering,SG,90000,2021-06-20
E004,Dina,HR,JK,60000,2018-04-10
E005,Eve,Marketing,SG,62000,2022-01-05
EOF

vd ~/github/practice-folder/visidata/01-loading/01-employees.csv

Rename a Single Column (^)

^ # opens input prompt with current name pre-filled

Example — rename emp_id to id:

# Move cursor to 'emp_id' column
^
# Input prompt: emp_id
# Clear and type: id
# Press Enter

Before:

emp_id name department
E001 Alice Engineering

After:

id name department
E001 Alice Engineering

The renamed column is now available in expressions as id:

=
# Enter: id + '_' + department
# Name: employee_key
# Result: E001_Engineering, E002_Marketing, ...

Rename to Current Cell Value (z^)

z^ # renames the current column to the value in the current cell

Use case: Spreadsheets sometimes have the real column name stored in the first data row, not the header.

# Move to the column with wrong header
# Move down to the row containing the intended name
z^ # header becomes that cell's value

Bulk Rename Unnamed Columns (g^)

g^ # rename ALL unnamed visible columns to values in the current row

Use case: Fixed-width files or legacy exports where headers are missing. The first data row contains the column names.

# Move cursor to the row that contains correct column names
g^ # all visible columns renamed to that row's values
# Then delete the now-redundant row: press d

Column Names with Spaces in Expressions

Column names with spaces cannot be used directly in expressions:

# Column named "Annual Salary" — WRONG:
=
# Enter: Annual Salary * 0.10 ← syntax error

# CORRECT — use dict syntax:
=
# Enter: row['Annual Salary'] * 0.10

Best practice: Always rename columns to remove spaces before writing expressions:

# Move to 'Annual Salary' column
^
# Enter: annual_salary ← snake_case, no spaces

# Now you can write:
=
# Enter: annual_salary * 0.10

Quick Reference

KeyAction
^Rename current column
z^Rename column to current cell value
g^Bulk rename all unnamed columns to current row values

Hands-On Practice

vd ~/github/practice-folder/visidata/01-loading/01-employees.csv

# 1. Rename 'emp_id' → 'id': move to column → ^ → type id → Enter
# 2. Try z^ on a cell — column header becomes that cell's value

What's Next