# Data & CSV

This vault has a small [expenses.csv](expenses.csv) next to this note. Click it in the sidebar and it opens as a real grid, not a wall of commas.

## The grid

The file opens as a table: header row on top, numbers right-aligned, and every cell editable in place. Click a cell, type, click away, and wander rewrites exactly that one line of the file, nothing else. Your git diff shows one changed line.

The eye button shows the raw text (also editable), and the split button shows both side by side, edits flow both ways.

## Columns and their shapes

With a csv open, the Outline tab in the right panel lists the columns instead of headings. Each one is typed by looking at the data itself: `amount` reads as numeric, `category` as a handful of values, `month` as dates. Click a column and you get a small chart of its distribution with the numbers underneath: min, max, mean for numbers, the top values for categories.

## Ask the file a question

The terminal button above the grid opens a query line. It speaks SQL, and the open file is the table `this`:

    select category, sum(amount) as total
    from this
    group by 1
    order by 2 desc

The answer replaces the grid until you press escape. Nothing is imported anywhere, the query runs on the file where it lives.

## Big files

A csv too large to edit comfortably (say, gigabytes) still opens instantly. The grid becomes a read-only window that streams rows as you scroll, sorting by a column re-queries the file rather than loading it, and the row count fills in as it finishes counting. Everything above, columns, charts, queries, works the same at any size.

## Feeding a note

With the notebook feature on, a `data` block names a csv into your note's variables:

```data
spend = demo/expenses.csv
```

Run it, and downstream blocks can use `spend` like any other value: a `plot` block can chart it, a `calc` block can compute with it, a `sql` block can join it. The name is written in the block, so the note says exactly where its numbers come from.

Back to [[Welcome]].
