Go's standard library is good at the data engineering half of data science: reading and writing CSV, JSON and other formats, streaming large files, grouping and sorting with the slices and maps packages, basic maths with math, and parallel processing with goroutines. It has no data frames, plotting or machine learning, so for statistics and charts you add libraries such as Gonum.
Go is a strong choice when the analysis must run as a fast, deployable service or process data too large for a script. For exploratory work in notebooks, Python is still more convenient.
| Task | Packages |
|---|---|
| Read and write tabular data | encoding/csv, bufio, os |
| Structured data | encoding/json, encoding/xml, encoding/gob |
| Sort, search, group | slices, maps, sort, cmp (Go 1.21+) |
| Maths | math, math/big, math/rand/v2 |
| Parallel processing | goroutines, channels, sync, context |
| Databases | database/sql |
| Text and time | strings, strconv, time, text/template |
| Measuring performance | testing benchmarks, runtime/pprof |
csv.Reader reads one record at a time, so memory use stays flat even for files with millions of rows. Parse each field with strconv and handle bad rows explicitly.
For very large inputs, process each record inside the loop instead of appending to a slice.
Group-by and aggregation need no library: a map plus a loop does it. Since Go 1.21 the slices and maps packages remove most of the sorting boilerplate.
maps.Values returns an iterator, which for ... range accepts from Go 1.23. Because map iteration order is random, sort before printing so results are repeatable.
The standard library has math for basic functions but no statistics package. Simple measures take a few lines.
Guard against empty slices in real code. For matrices, regression, distributions and hypothesis tests, use the Gonum modules (gonum.org/v1/gonum/stat, mat) rather than writing your own numerics.
Analysis of independent chunks parallelises well. Split the data, give each worker a chunk and merge the partial results. Use sync.WaitGroup and per-worker results to avoid locks.
This uses range-over-int and per-iteration loop variables, both from Go 1.22. Each goroutine writes only its own element of partial, so there is no data race. Check with go test -race.
| Need | Common choice |
|---|---|
| Statistics, linear algebra, optimisation | Gonum |
| Data frames | gota or dataframe-go (check maintenance status) |
| Charts | gonum/plot, go-echarts |
| Columnar and Parquet files | Apache Arrow for Go |
| Interactive notebooks | Jupyter kernels such as gophernotes |
| Machine learning | Bindings to ONNX Runtime or calling a Python service |
Write a benchmark before optimising, then profile where the time goes.
Typical wins are preallocating slices with make([]T, 0, n), reading with a buffered reader, avoiding repeated string conversions and processing a stream instead of loading the whole file.
It is good for data pipelines, services and high-throughput processing. For exploration, plotting and machine learning, Python has far more libraries, and many teams use Go for the production side.
Not in the standard library. Community data frame packages exist, and Gonum covers numerical work, but none matches pandas in breadth.
Use csv.Reader.Read in a loop and process each record as you go, rather than ReadAll.
Use gonum.org/v1/plot for static images or go-echarts for interactive HTML charts.
Use encoding/csv, encoding/json and bufio to ingest data, slices, maps and generics to group and sort it, and goroutines to scale it across cores. Add Gonum for serious statistics and plotting libraries for charts. Benchmark and profile before tuning, and keep Python for exploratory analysis.