Skip to main content
Version: 7.9

system.dataset.fromCSV

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

Integer = I

String = str

Double = D

Date = date

Long = L

Short = S

Float = F

Boolean = B

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

TypeParameterDescription
StringcsvA string holding a CSV dataset.

Returns

Dataset - A new dataset.

Scope

All

Code Examples

Example 1
# This example takes the dataset from a table component and formats the dates to look like Fri, Jan 22, 2018.

data = event.source.parent.getComponent('Table').data
formattedData = system.dataset.formatDates(data, "EEE, MMM d, yyyy")
Example 2
# In this example it is assumed that the CSV file being read was a dataset that was previously exported using system.dataset.toCSV:

# 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