Skill Tracer
Skills › Scientific Agent Skills › vaex › core_dataframes.md

core_dataframes.md

104 lines · skills/vaex/references/core_dataframes.md at 5f2bc03

Open on GitHub
1# Core DataFrames and loading
2
3Targets core 4.19.0. [API](https://vaex.io/docs/api.html),
4[I/O guide](https://vaex.io/docs/guides/io.html), and the released package source
5were checked on 2026-10-01. Examples in each reference run sequentially unless marked illustrative.
6

Core DataFrames and loading

Targets core 4.19.0. API, I/O guide, and the released package source were checked on 2026-10-01. Examples in each reference run sequentially unless marked illustrative.

Raw lines 1 to 6
7## Construct and inspect a small fixture
8
9```python
10import numpy as np
11import pandas as pd
12import pyarrow as pa
13import vaex
15df = vaex.from_arrays(x=np.arange(6.), y=np.arange(6.) ** 2,
16 category=np.array(['A', 'B'] * 3))
17from_dict = vaex.from_dict({'x': [1, 2], 'label': ['a', 'b']})
18from_arrow = vaex.from_arrow_table(pa.table({'x': [1, 2], 'y': [3, 4]}))
19from_pandas = vaex.from_pandas(pd.DataFrame({'x': [1, 2]}), copy_index=False)
20assert from_dict.shape == (2, 2)
21assert from_arrow.x.tolist() == [1, 2]
22assert from_pandas.get_column_names() == ['x']
23print(df.shape, len(df), df.get_column_names(), df.dtypes)
24print(df.head(2)) # Vaex DataFrame, not pandas
25print(df.tail(2))
26row = dict(zip(df.get_column_names(), df[0])) # integer indexing returns a list
27assert row['x'] == 0
28```
30These constructors start from in-memory objects. Wrapping a pandas frame or Arrow
31table does not retroactively make its existing allocation out of core. Object columns
32must have consistent types; verify null and timestamp representations after conversion.
33`df.describe()` executes summary work and may be expensive across many columns.
34`df.byte_size()` estimates column bytes; it is not process RSS, peak memory, or OS page-cache usage.

Construct and inspect a small fixture

import numpy as np
import pandas as pd
import pyarrow as pa
import vaex

df = vaex.from_arrays(x=np.arange(6.), y=np.arange(6.) ** 2,
                      category=np.array(['A', 'B'] * 3))
from_dict = vaex.from_dict({'x': [1, 2], 'label': ['a', 'b']})
from_arrow = vaex.from_arrow_table(pa.table({'x': [1, 2], 'y': [3, 4]}))
from_pandas = vaex.from_pandas(pd.DataFrame({'x': [1, 2]}), copy_index=False)
assert from_dict.shape == (2, 2)
assert from_arrow.x.tolist() == [1, 2]
assert from_pandas.get_column_names() == ['x']
print(df.shape, len(df), df.get_column_names(), df.dtypes)
print(df.head(2))                  # Vaex DataFrame, not pandas
print(df.tail(2))
row = dict(zip(df.get_column_names(), df[0]))  # integer indexing returns a list
assert row['x'] == 0

These constructors start from in-memory objects. Wrapping a pandas frame or Arrow table does not retroactively make its existing allocation out of core. Object columns must have consistent types; verify null and timestamp representations after conversion. df.describe() executes summary work and may be expensive across many columns. df.byte_size() estimates column bytes; it is not process RSS, peak memory, or OS page-cache usage.

Raw lines 7 to 35
36## Open existing data
38Illustrative file paths (create or obtain compatible files first):
40```python
41hdf = vaex.open('measurements.hdf5')
42arrow = vaex.open('measurements.arrow')
43parquet = vaex.open('measurements.parquet')
44csv = vaex.open('measurements.csv')
45parts = vaex.open('part-*.hdf5')
46explicit_parts = vaex.open_many(['part-001.hdf5', 'part-002.hdf5'])
47```
49Local compatible HDF5 and uncompressed Arrow buffers can be memory mapped; metadata
50and accessed pages still use memory. Parquet decoding/compression and compressed
51Feather require buffers. Lazy CSV indexes the file and infers a schema, then reparses
52needed chunks. It is not a no-read open; compressed CSV is unsupported by that lazy reader.
53Use explicit types for identifiers and mixed/missing columns. See [I/O](io_operations.md).
55`vaex.example()` is an N-body satellite-accretion simulation, not NYC taxi data.
56`vaex.datasets.iris()` and `.titanic()` may download/cache data. Use synthetic fixtures
57when network access or a dataset download is unnecessary; record dataset provenance
58when using an example scientifically.

Open existing data

Illustrative file paths (create or obtain compatible files first):

hdf = vaex.open('measurements.hdf5')
arrow = vaex.open('measurements.arrow')
parquet = vaex.open('measurements.parquet')
csv = vaex.open('measurements.csv')
parts = vaex.open('part-*.hdf5')
explicit_parts = vaex.open_many(['part-001.hdf5', 'part-002.hdf5'])

Local compatible HDF5 and uncompressed Arrow buffers can be memory mapped; metadata and accessed pages still use memory. Parquet decoding/compression and compressed Feather require buffers. Lazy CSV indexes the file and infers a schema, then reparses needed chunks. It is not a no-read open; compressed CSV is unsupported by that lazy reader. Use explicit types for identifiers and mixed/missing columns. See I/O.

vaex.example() is an N-body satellite-accretion simulation, not NYC taxi data. vaex.datasets.iris() and .titanic() may download/cache data. Use synthetic fixtures when network access or a dataset download is unnecessary; record dataset provenance when using an example scientifically.

Raw lines 36 to 59
60## Expressions versus arrays
62```python
63expr = df.x ** 2 + df.y
64assert 'energy' not in df.get_column_names()
65df['energy'] = expr
66assert 'energy' in df.virtual_columns
67assert 'energy' not in df.get_column_names(virtual=False)
68assert np.isclose(df.energy.mean(), 55 / 3) # computes now
69preview = df[:3].energy.to_numpy() # bounds rows before evaluation
70assert preview.tolist() == [0., 2., 8.]
71```
73Expressions defer the per-row calculation, but reductions without `delay=True`
74execute. `.values` may return NumPy, masked NumPy, or Arrow depending on dtype;
75`.to_numpy()`, `.tolist()` and `.to_pandas_df()` materialize their requested data.
76For larger-than-RAM data, select a bounded subset or iterate chunks before conversion.
77A filter is a view with its own selection/mask state, not a guarantee of zero allocation.

Expressions versus arrays

expr = df.x ** 2 + df.y
assert 'energy' not in df.get_column_names()
df['energy'] = expr
assert 'energy' in df.virtual_columns
assert 'energy' not in df.get_column_names(virtual=False)
assert np.isclose(df.energy.mean(), 55 / 3)  # computes now
preview = df[:3].energy.to_numpy()          # bounds rows before evaluation
assert preview.tolist() == [0., 2., 8.]

Expressions defer the per-row calculation, but reductions without delay=True execute. .values may return NumPy, masked NumPy, or Arrow depending on dtype; .to_numpy(), .tolist() and .to_pandas_df() materialize their requested data. For larger-than-RAM data, select a bounded subset or iterate chunks before conversion. A filter is a view with its own selection/mask state, not a guarantee of zero allocation.

Raw lines 60 to 78
79## Copies, columns and rows
81```python
82copy = df.copy() # shares underlying data
83subset = df[['x', 'energy']][:3] # column selection and row slice
84assert subset.shape == (3, 2)
85renamed = df.copy()
86new_name = renamed.rename('x', 'distance') # mutates names; returns the new name
87assert new_name == 'distance'
88assert 'distance' in renamed.get_column_names()
89assert 'x' in df.get_column_names()
90reduced = df.drop('category')
91assert 'category' not in reduced.get_column_names()
92combined = vaex.concat([df[:2], df[2:]])
93assert len(combined) == len(df)
94sample = df.sample(n=3, random_state=7).to_pandas_df()
95assert len(sample) == 3
96```
98Use bracket access for columns that collide with frame methods, such as `df['label']`.
99`copy(deep=True)` and `df.row()` are not core 4.19.0 methods. Export and reopen a
100snapshot for independent persisted data; explicit array copies are only suitable for
101bounded datasets. For horizontal combination, validate row IDs/order or perform an
102explicit key join. Assigning another frame's expression is not an identity alignment.
103`vaex.concat` resolves schemas; inspect types and counts rather than assuming exact
104schema equality. Record units outside a plain numeric column when the source carries them.

Copies, columns and rows

copy = df.copy()                     # shares underlying data
subset = df[['x', 'energy']][:3]      # column selection and row slice
assert subset.shape == (3, 2)
renamed = df.copy()
new_name = renamed.rename('x', 'distance')  # mutates names; returns the new name
assert new_name == 'distance'
assert 'distance' in renamed.get_column_names()
assert 'x' in df.get_column_names()
reduced = df.drop('category')
assert 'category' not in reduced.get_column_names()
combined = vaex.concat([df[:2], df[2:]])
assert len(combined) == len(df)
sample = df.sample(n=3, random_state=7).to_pandas_df()
assert len(sample) == 3

Use bracket access for columns that collide with frame methods, such as df['label']. copy(deep=True) and df.row() are not core 4.19.0 methods. Export and reopen a snapshot for independent persisted data; explicit array copies are only suitable for bounded datasets. For horizontal combination, validate row IDs/order or perform an explicit key join. Assigning another frame's expression is not an identity alignment. vaex.concat resolves schemas; inspect types and counts rather than assuming exact schema equality. Record units outside a plain numeric column when the source carries them.

Raw lines 79 to 104