Reading and writing CSV files

Reading and writing a CSV file in Breeze is really a breeze. We just have two functions in breeze.linalg package to play with. They are very intuitively named csvread and csvwrite.

In this recipe, you'll see how to:

  1. Read a CSV file into a matrix
  2. Save selected columns of a matrix into a new matrix
  3. Write the newly created matrix into a CSV file
  4. Extract a vector out of the matrix
  5. Write the vector into a CSV

How it works...

There are just two functions that we need to remember in order to read and write data from and to CSV files. The signatures of the functions are pretty straightforward too:

csvread(file, separator, quote, escape, skipLines)
csvwrite(file, mat, separator, quote, escape, skipLines)

Let's look at the parameters ...

Get Scala: Guide for Data Science Professionals now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.