This function is used in Python Scripting.

Description

Converts a dataset stored in a CSV formatted string to a dataset that can be immediately assignable to a dataset property in your project.  Usually this is used in conjunction with  system.file.readFileAsString  when reading in a CSV file that was exported using  system.dataset.toCSV .  The CSV string must be formatted in a specific way:

#NAMES
Col 1,Col 2,Col 3
#TYPES
I,str,D
#ROWS,6
44,Test Row 2,1.8713151369491254
86,Test Row 3,97.4913421614675
0,Test Row 8,20.39722542161364
78,Test Row 9,34.57127071614745
20,Test Row 10,76.41114659745085
21,Test Row 13,13.880548366871926

The first line must be #NAMES

The second line must list the names of the columns of the dataset separated by commas

The third line must be #TYPES

The fourth line must list the type of each column of the dataset in order, separated by commas

Data TypeAlias
byte.classbyt
short.classs
int.classi
long.classl
float.classf
double.classd
bool.classb
Byte.classByt
Short.classS
Integer.classI
Long.classL
Float.classF
Double.classD
Boolean.classB
Object.classO
Color.classclr
Date.classdate
Cursor.classcur
Dimension.classdim
Rectangle.classrect
Point.classpt
String.classstr
Border.classborder

The fifth line must be #ROWS followed by a comma and then the number of rows of data (i.e. #ROWS, 6)

The following lines will be your data, each column value separated by a comma; each row on a separate line.  The number of rows must match what was specified on line 5

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax

system.dataset.fromCSV( csv )

  • Parameters

String csv A string holding a CSV dataset in the format outlined above. 

  • Returns

Dataset A new dataset.

  • Scope

Gateway, Vision Client, Perspective Session

Code Examples
Code Snippet
# In this example it is assumed that the CSV file being read was a dataset 
#that was previously exported using system.dataset.toCSV with the forExport flag set to True:
# Specify file path.
file_path = "C:\\my_dataset.csv"
# Read in the file as a string.
data_string = system.file.readFileAsString(file_path)
# Convert the string to a dataset and store in a variable.
data = system.dataset.fromCSV(data_string)
# Assign the dataset to a table.
event.source.parent.getComponent('Table').data = data
Keywords

system dataset fromCSV, dataset.fromCSV