DataFrame Operations (DataFrames.jl)
Filter, transform, group, and join tabular data with DataFrames.jl.
Code
using DataFrames, Statistics
df = DataFrame(
name = ["Alice", "Bob", "Carol", "Dave"],
dept = ["Eng", "Eng", "Sales", "Sales"],
salary = [90, 85, 70, 75],
years = [5, 3, 7, 2],
)
# Filter rows
eng = filter(:dept => ==("Eng"), df)
high = filter([:salary, :years] => (s, y) -> s > 80 && y > 2, df)
# Add / transform columns (with! is in-place)
transform!(df, :salary => ByRow(x -> x * 1.1) => :raise)
transform!(df, [:salary, :years] => ByRow((s, y) -> s / y) => :per_year)
# Group + summarize
gdf = groupby(df, :dept)
combine(gdf, :salary => mean => :avg_salary,
:salary => sum => :total,
nrow => :headcount)
# Sort
sort!(df, :salary, rev=true)
# Join
bonuses = DataFrame(name=["Alice","Bob","Eve"], bonus=[10, 5, 8])
joined = innerjoin(df, bonuses, on = :name)Explanation
DataFrames.jl mirrors R's dplyr / Python's pandas but uses Julia's types for speed. The column => function => target syntax of transform/combine is the central idiom: it specifies the input column(s), the transformation (often wrapped in ByRow to apply row-wise), and the output column name. groupby + combine is the split-apply-combine pattern for grouped summaries.
More Julia Snippets
Broadcasting & Vectorization
Apply a function element-wise over arrays with dot syntax and @.
Multiple Dispatch
Select methods by the runtime types of all arguments, not just the receiver.
Parametric Types & Performance
Define generic, type-stable containers that compile to specialized code.
Macros & Expressions
Manipulate Julia syntax trees as first-class data via :expr and macro.
Multi-threading & Distributed Compute
Parallelize loops with @threads and offload tasks with @spawn / pmap.
Performance Tips: @inbounds, @fastmath, views
Write Julia that runs at C speed by removing bounds checks, avoiding allocations, and using views.