If you are coming to Julia from office software, the transition is not as difficult as you may think. Try this.
# ==============================================================================
# Julia Starter Template for Excel Users
# Mission: Load a CSV, clean it, and run a "Pivot Table" summary.
# ==============================================================================
using DataFrames
using Statistics
using XLSX
# 1. LOAD DATA
# In Excel: File > Open
# In Julia: We read the file into a 'DataFrame' (think of it as a virtual sheet)
file_path = "your_data_file.csv"
# Note: Check if file exists before loading
if isfile(file_path)
df = DataFrame(XLSX.readtable(file_path, 1))
println("Successfully loaded $(nrow(df)) rows.")
else
# Create dummy data for testing if no file is present
df = DataFrame(
Region = ["East", "West", "East", "North", "West"],
Sales = [1200.50, 850.00, 2100.00, 400.25, 1500.75],
Category = ["Tech", "Office", "Tech", "Furniture", "Office"]
)
println("Using sample data for demonstration...")
end
# 2. THE "CALCULATED COLUMN"
# adjust to your vareiable names
# In Excel: =B2 * 0.08 (Tax Calculation)
# In Julia: Use the '.' for element-wise math (applying to every row at once)
df.Tax = df.Sales .* 0.08
# 3. FILTERING
# In Excel: Data > Filter > "Tech"
# In Julia: Create a subset
tech_sales = subset(df, :Category => x -> x .== "Tech")
# 4. THE "PIVOT TABLE"
# In Excel: Insert > Pivot Table (Rows: Region, Values: Sum of Sales)
# In Julia: GroupBy and Combine
pivot_summary = combine(groupby(df, :Region),
:Sales => sum => :Total_Sales,
:Sales => mean => :Average_Ticket
)
# 5. EXPORT
# In Excel: File > Save As
CSV.write("julia_report_output.csv", pivot_summary)
println("--- Summary Report ---")
show(pivot_summary)
which will output
# Julia Starter Template for Excel Users
# Mission: Load a CSV, clean it, and run a "Pivot Table" summary.
# ==============================================================================
using DataFrames
julia> using CSV
julia> using Statistics
julia> # 1. LOAD DATA
# In Excel: File > Open
# In Julia: We read the file into a 'DataFrame' (think of it as a virtual sheet)
file_path = "your_data_file.csv"
"your_data_file.csv"
julia> # Note: Check if file exists before loading
if isfile(file_path)
df = CSV.read(file_path, DataFrame)
println("Successfully loaded $(nrow(df)) rows.")
else
# Create dummy data for testing if no file is present
df = DataFrame(
Region = ["East", "West", "East", "North", "West"],
Sales = [1200.50, 850.00, 2100.00, 400.25, 1500.75],
Category = ["Tech", "Office", "Tech", "Furniture", "Office"]
)
println("Using sample data for demonstration...")
end
Using sample data for demonstration...
julia> # 2. THE "CALCULATED COLUMN"
# In Excel: =B2 * 0.08 (Tax Calculation)
# In Julia: Use the '.' for element-wise math (applying to every row at once)
df.Tax = df.Sales .* 0.08
5-element Vector{Float64}:
96.04
68.0
168.0
32.02
120.06
julia> # 3. FILTERING
# In Excel: Data > Filter > "Tech"
# In Julia: Create a subset
tech_sales = subset(df, :Category => x -> x .== "Tech")
2×4 DataFrame
Row │ Region Sales Category Tax
│ String Float64 String Float64
─────┼────────────────────────────────────
1 │ East 1200.5 Tech 96.04
2 │ East 2100.0 Tech 168.0
julia> # 4. THE "PIVOT TABLE"
# In Excel: Insert > Pivot Table (Rows: Region, Values: Sum of Sales)
# In Julia: GroupBy and Combine
pivot_summary = combine(groupby(df, :Region),
:Sales => sum => :Total_Sales,
:Sales => mean => :Average_Ticket
)
3×3 DataFrame
Row │ Region Total_Sales Average_Ticket
│ String Float64 Float64
─────┼─────────────────────────────────────
1 │ East 3300.5 1650.25
2 │ West 2350.75 1175.38
3 │ North 400.25 400.25
julia> # 5. EXPORT
# In Excel: File > Save As
CSV.write("julia_report_output.csv", pivot_summary)
"julia_report_output.csv"
julia> println("--- Summary Report ---")
--- Summary Report ---
julia> show(pivot_summary)
3×3 DataFrame
Row │ Region Total_Sales Average_Ticket
│ String Float64 Float64
─────┼─────────────────────────────────────
1 │ East 3300.5 1650.25
2 │ West 2350.75 1175.38
3 │ North 400.25 400.25
julia>