A set of CSV conversion tools I made for the Belgian Biodiversity Platform.
Converts a matrix CSV file into a list CSV file.
Typically a matrix with n by m elements will result in a n*m rows in the generated list.
List rows will consist of starting cells from the matrix row, plus one 'column' cell and one 'value' cell from the matrix.
Empty values in the matrix will not result in a row.
ruby matrix2list.rb inpath outpath startAt
Where:
- inpath: the input path of the matrix
- outpath: the output path of the generated list
- startAt: the index of first column to be converted: all previous columns are copied to each list row, all remaining columns (starting with this one) will result in a list row.
run ruby matrix2List.rb examples/matrix.cvs examples/list.csv 2
- matrix.csv hold two dimensions array, one column per month
- list.csv hold the generated list data, one row per month
- 2 means that jan is the first column of the two dimensions array
Converts back a lsit CSV file into a matrix CSV file.
Typically, a list of n*m rows will result in a n by m two dimensions generated matrix.
Matrix rows will consist of starting cells from the list row, plus m columns.
Values are supposedly placed as the last cell.
ruby list2matrix.rb inpath outpath columnIndex
Where:
- inpath: the input path of the list
- outpath: the output path of the generated matrix
- columnIndex: the index of column field: all distinct values of this field will result in an additional column in the matrix
run ruby list2matrix.rb examples/list.csv examples/matrix.csv 2
- list.csv hold same data as a list, one row per month
- matrix.csv hold the generated two dimensions array, one column per month
- 2 means that the month column should be used to build the matrix
CSVMultiTools are written in Ruby language. Please use Ruby 1.9.3 or more recent version of the language. They are based on and therefore require CSV rubygem.