Go processes and analyzes data well because it combines fast compiled code, a strong standard library for text, JSON, CSV and sorting, and cheap concurrency with goroutines and channels. For heavy numerical or statistical work you add libraries such as Gonum, or use a dataframe package, while Go itself handles ingestion, transformation and pipelines.
This article walks through reading and parsing data, transforming it with generics and the slices and maps packages, processing it in parallel with worker pools, and doing basic statistics.
Go is not a notebook language like Python, but it is a good fit when data work must be fast, deployed as a single binary, or run as part of a service.
| Task | Tool |
|---|---|
| Read text and logs line by line | bufio.Scanner, bufio.Reader |
| CSV, JSON, XML, gob | encoding/csv, encoding/json, encoding/xml, encoding/gob |
| Sorting, searching, min and max | slices, sort (Go 1.21+ for slices) |
| Maps and key utilities | maps, built-in map |
| Parallel work | goroutines, channels, sync.WaitGroup, errgroup |
| Numerics, matrices, statistics | Gonum (gonum.org/v1/gonum) |
| Dataframes | Third-party packages such as gota or dataframe-go |
| Columnar and big-data formats | Apache Arrow and Parquet Go libraries |
Stream large inputs instead of loading them whole. This program reads a CSV file of sales rows and parses each record:
For JSON lines or very large arrays, use json.NewDecoder and call Decode repeatedly so memory stays flat.
Since Go 1.18 you can write reusable generic helpers, and Go 1.21 added the slices and maps packages. Here is a group-and-sum aggregation and a sorted report:
maps.Keys returns an iterator in Go 1.23 and later, and slices.SortedFunc collects and sorts it. On Go 1.21 and 1.22, maps.Keys lived in golang.org/x/exp/maps and returned a slice, so check your version. Map iteration order is random, so sort keys before printing.
CPU-bound or I/O-bound steps benefit from a worker pool. Workers read jobs from one channel and send results on another:
The producer closes jobs when it is done, a separate goroutine closes results after all workers finish, and the main goroutine drains results. For tasks that can fail, use golang.org/x/sync/errgroup to collect the first error and cancel the others. Size the pool near runtime.NumCPU() for CPU-bound work.
The standard library has no statistics package, so write small helpers for basics or use Gonum for more:
This is the population standard deviation. For sample statistics divide by n-1. With Gonum, stat.Mean, stat.StdDev, stat.Correlation and the mat package for matrices cover most needs. Guard against empty slices, which would divide by zero.
make([]T, 0, n) when you know the size.bufio instead of reading whole files.go test -bench and pprof.sync.Pool only where profiling shows allocation pressure.For exploratory analysis, Python and R have richer tooling. Go is strong for production data pipelines, ETL services, log processing and anything needing speed, low memory and easy deployment.
Gonum is the most widely used suite, with matrices, statistics, optimization and plotting packages.
Read it as a stream with bufio.Scanner or a CSV or JSON decoder, process each record, and write results out incrementally. Raise the scanner buffer with Scanner.Buffer if lines are long.
For CPU-bound work, about runtime.NumCPU(). For I/O-bound work you can use more, but bound them with a worker pool or semaphore so you do not overload downstream systems.
Go processes data by streaming input with bufio, encoding/csv and encoding/json, transforming it with generics and the slices and maps packages, and parallelizing with worker pools of goroutines. Use Gonum for statistics and matrices, preallocate memory, and profile before tuning.