Home arrow Tutorials arrow Loading data from CSV files

CONTENT WARNING

This site refers to our older, server-based product. If you are interested in our new, Excel-based product, please see our main web site at http://www.nextanalytics.com

Loading data from CSV files

Comma-Separated-Value (CSV) files are a very popular way to move data from one application to another, and nextanalytics provides three possible ways to load these files. Which method you choose depends on whether you have control over the file, and whether it has a header row with the field names for each column.

Column definition

When importing data into nextanalytics, you have to specify whether the column will be a Row Label, or any number of Text Columns or Numeric Columns. The Row Label and Text Columns are treated the same - as columns of text - and can be used for filtering, sorting, grouping or as labels. You need at least one column of text, and the first one is refered to as the Row Label. Numeric Columns are used in mathematical analysis, and you need at least one.

Columns are defined using one of the roles 'rowlabel_', 'text_' or 'numeric_'.  An additional role 'ignore_' is used to exclude the column from being loaded.

Scenario 1 - Full control over the source file

When you have total control over the source file, you can create a first row that includes the role definitions as prefixes to the column names. This allows nextanalytics to determine the column names and types automatically, using the simple AddData script command.

File: example1.csv
  1. rowlabel_Name,text_Region,numeric_Sales
  2. Tom Clancy,NorthEast,12000
  3. Bob Ridgeback,South,14000

The file 'example1.csv' here can be loaded into nextanalytics using the simple script command:

AddData,example1.csv

AddData , filename

Scenario 2 - Using an existing file with a header row

When you have an existing file with a header row, but you can't change the header row to include the definition keys, you would use the ImportData command and identify the filename, the row number that contains the header with the field names (usually the first row - number 0) , and the first row of the data (usually the second row - number 1), and finally a list of roles for each column in the order that they appear in the file.

File: example2.csv
  1. Name,Region,Sales
  2. Tom Clancy,NorthEast,12000
  3. Bob Ridgeback,South,14000

The file 'example2.csv' can be loaded into nextanalytics using the script command:

ImportData,examples2.csv,0,1,RowLabel_,Text_,Numeric_

ImportData, filename , header row number , data row number, column role [, column role…]

Scenario 3 - Using an existing file without a header row

When you have an existing file that does not have a header row, you would use the ImportDataNoHeader command and identify the filename, a list of titles for each of the columns, and a list of roles for each of those columns in the order that they appear in the file.

File: example3.csv
  1. Tom Clancy,NorthEast,12000
  2. Bob Ridgeback,South,14000

The file 'example2.csv' can be loaded into nextanalytics using the script command:

ImportDataNoHeader,examples3.csv,"Name,Region,Sales","RowLabel_,Text_,Numeric_"

ImportDataNoHeader , filename , "column title [, column title]", "column role [, column role...]"