This directory contains practical examples demonstrating the capabilities of VFrames, a high-performance DataFrame library for V powered by DuckDB.
Data Loading and Exploration
Demonstrates the fundamental operations:
- Initializing a vframes context (in-memory or persisted)
- Loading data from records (array of maps)
- Exploring DataFrame structure:
shape()- Get dimensions (rows, columns)columns()- List column namesdtypes()- Show data typeshead(n)- View first n rowstail(n)- View last n rowsinfo()- Show column informationdescribe()- Summary statistics
- Column operations:
subset(cols)- Select specific columnsadd_column(name, expr)- Add calculated columnsadd_prefix(prefix)/add_suffix(suffix)- Rename columnsdelete_column(col)- Remove columns
slice(start, end)- Extract row ranges
Run: v run examples/01_basic_usage.v
Grouping, Aggregations, and Transformations
Shows advanced data analysis capabilities:
- Grouping operations:
group_by(dimensions, metrics)- Group and aggregate- Multi-column grouping
- Mathematical operations:
add(n),sub(n),mul(n),div(n)- Arithmeticadd_column(name, expr)- Calculated columns
- Statistical functions:
sum(opts),mean(opts),median(opts)- Central tendencystd(),var()- Variabilitycount(),nunique()- Counting
- Complex filtering:
query(sql_expression)- SQL-like queries
- Finding extremes:
nlargest(n),nsmallest(n)- Top/bottom records
- Value analysis:
value_counts()- Frequency counts
Run: v run examples/02_data_analysis.v
Missing Values, Exports, and Complex Operations
Covers advanced features:
- Missing value handling:
isna(),notna()- Detect missing valuesdropna(opts)- Remove rows with NAfillna(opts)- Fill with valuesffill(),bfill()- Forward/backward fill
- Data transformations:
abs()- Absolute valuesround(decimals)- Roundingclip(min, max)- Limit to rangepow(n, opts)- Power transformationastype(type_map)- Type conversion
- Data export:
to_csv(path, opts)- CSV exportto_json(path)- JSON exportto_parquet(path)- Parquet export
- File operations:
read_auto(path)- Auto-detect format (CSV/JSON/Parquet)
- Value operations:
isin(values)- Check membershipreplace(old, new)- Replace values
Run: v run examples/03_advanced_features.v
-
Install vframes:
v install https://github.com/rodabt/vduckdb v install https://github.com/rodabt/vframes
-
Set DuckDB library path:
export LIBDUCKDB_DIR=/path/to/duckdb/lib -
Run an example:
v run examples/01_basic_usage.v
The directory includes sample data files for testing:
titanic.parquet- Classic Titanic dataset in Parquet formatpeople-500000.csv- Large CSV file with 500,000 recordsdata.json- Sample JSON data file
All operations require a context that manages the DuckDB connection:
mut ctx := vframes.init() // In-memory (default)
mut ctx := vframes.init(location: 'data.db') // Persisted
defer { ctx.close() } // Always close when done// From records (requires x.json2)
data := [
{'name': json2.Any('Alice'), 'age': json2.Any(30)}
]
df := ctx.read_records(data)!
// From file (auto-detects format)
df := ctx.read_auto('data.csv')!Most operations return new DataFrames, enabling method chaining:
df := ctx.read_records(data)!
.add_column('doubled', 'age * 2')
.query('age > 25')!
.head(10)Use ! for error propagation and or blocks for handling:
df := ctx.read_auto('data.csv') or {
eprintln('Failed to load: ${err.msg()}')
return
}- Use persisted context for large datasets to avoid memory issues
- Chain operations to minimize intermediate DataFrames
- Use SQL queries via
query()for complex filtering - Leverage DuckDB - operations are executed in DuckDB's optimized engine
- Tutorial - Complete Pandas comparison guide
- Implementation Roadmap - API reference
- Tests - Unit tests showing usage patterns