Developing the Initial Version of colStats
Explore how to implement the csv2float() function in Go, reading CSV data via the csv package and converting a specified column to float64. Understand error handling and how to prepare data for calculations in CLI tools.
We'll cover the following...
We'll cover the following...
Implementing the csv2float() function
The last function we’ll implement in this file is the function csv2float() to parse
the contents of the CSV file into a slice of floating point numbers that we can
use to perform the calculations.
This function accepts two input parameters:
- An
io.Readerinterface representing the source of CSV data. - An
intrepresenting the column to extract data from.
It returns a slice of float64 numbers and a potential error:
Implementing the csv2float() function
This uses a similar pattern to what we’ve done previously; we’re providing
the io.Reader interface as the input parameter for ...