Close this search box.

Golang: Getting started with dataframes

In this article, we’re going to look at the qframe library to bring CSV data into a dataframe for simple data wrangling. This file:

  1. Imports the relevant packages
  2. Defines the file we are going to open (in this case emp.csv)
  3. We then use the ioutil library to read the file in. This gets ingested as a byte slice
  4. We then cast the byteslice to a string and trim the whitespace
  5. We then define a dataframe called f, which reads the contents of the CSV into the dataframe
  6. Next, we define a function called ‘converter’ which takes the value from the age column and doubles it. Inside the function we convert the integer value to string, using strconv. Note that the responses should be a pointer to the memory address.
  7. Finally, we create qf2, which is the application of that function to the dataframe named f, the result of which will be put into the output column

Here, we look at a group by function. The process is exactly the same until we define the function. This function, splits the age value into a slice of ints. It then loops through each row and sums the ages. It then returns that result to a new column. This is grouped by city, so in the end, we get the city & the sum of ages related to that city.

Share the Post:

Related Posts