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:
- Imports the relevant packages
- Defines the file we are going to open (in this case emp.csv)
- We then use the ioutil library to read the file in. This gets ingested as a byte slice
- We then cast the byteslice to a string and trim the whitespace
- We then define a dataframe called f, which reads the contents of the CSV into the dataframe
- 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.
- 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.