Loading a dataset "by Hand"

This tutorial tells use the DataFrame to load data "by Hand"

Loading data "by Hand"

While normally we load data from a file or another source, we can also create it by hand. We recommend making our data in excel or other sources, but document this possibility here for completeness. By default, there are six column types we can add, NumberColumn, BooleanColumn, IntegerColumn, TextColumn, AudioColumn, and DateColumn. Here are brief explanations on each valid column data entry we can use.

Column Types
NumberColumnNumberColumns allow us to insert both integers and decimal values into our data sets. NumberColumn numCol numCol:Add("1") numCol:Add("1.5")
BooleanColumnBooleanColumns allow us to insert true and false values into our data sets. BooleanColumn boolCol boolCol:Add(true) boolCol:Add(false)
IntegerColumnIntegerColumns allow us to insert whole numbers into our data sets. IntegerColumn intCol integerCol:Add(5) integerCol:Add(8)
TextColumnTextColumns allow us to insert strings/text into our data sets. TextColumn txtCol txtCol:("Mickey") txtCol:("Mouse")
AudioColumnAudioColumns allow us to insert audio files into our data sets. It takes in a string which is the file path of the audio file. AudioColumn* will accept both .ogg files and .wav files. AudioColumn aCol aCol:Add("..\Audio\squeak.mp4") aCol:Add("..\Audio\beep.mp4")
DateColumn**DateColumns allow us to insert dates into our data sets. DateColumn dCol dCol:Add("11/2/2022") dCol:Add("11/3/2022")

**DateColumn was added in Quorum 10.0.

For this example, we will be creating a dataset that incorporates a selection of the data types we can insert. What we want to start off is creating a DataFrame object to load our dataset. We will go ahead and name it 'frame.' Now, let us create the columns of the data types: number, boolean, integer, and text.

We should have the following code:

*Note that AudioColumns cannot be used with the ToText() function with DataFrames.

Code Example

//We need the DataFrame class to load in files for Data Science operations.
use Libraries.Compute.Statistics.DataFrame
use Libraries.Compute.Statistics.Columns.NumberColumn
use Libraries.Containers.Array
use Libraries.Compute.Statistics.DataFrameColumn
use Libraries.Compute.Statistics.Columns.TextColumn
use Libraries.Compute.Statistics.Columns.BooleanColumn
use Libraries.Compute.Statistics.Columns.IntegerColumn

//Create a DataFrame, which is essentially a table that understands 
//more information about the data that is being loaded.
DataFrame frame

NumberColumn numCol
TextColumn textCol
BooleanColumn boolCol
IntegerColumn intCol

Now that we have our data columns, we can simply use the Add(type element) with the respective column object we have created. Our Add(type element) can be used with all the different columns and will add our element of the respective data type within the data set. Here, we will add two elements to each column.



Now that we have populated our dataset, we would like to insert them into the DataFrame. Doing this step actually helps construct the elements and form it into a CSV-style type of dataset. We can achieve this by calling the AddColumn(dataColumn type) function with our DataFrame 'frame' object. Here is a brief description of how AddColumn(dataColumn type) works.

AddColumn Function
frame:AddColumn(dataColumn type)This function takes in a data column of either: text, boolean, number, audio, integer, or date and constructs the column. It forms one column each instance it is called. booleanColumn boolCol boolCol:Add(true) boolCol:Add(true) boolCol:Add(false) frame:AddColumn(boolCol)

For our case, calling AddColumn() will add the two elements of each type into a DataFrame. Afterwards, we can view our data set onto the console by calling the ToText() function with our 'frame' object as well. We will now be inserting the elements we have added onto our data frame as follows and displaying them onto the console:


output frame:ToText()

Try it Yourself!

Press the blue run button to execute the code in the code editor. Press the red stop button to end the program. Your program will work when the console outputs "Build Successful!"

Congratulations! We have successfully created our first dataset. To view another example of loading data by hand we can reference it here. To add on, here is another example of using the AudioColumn here.

Next Tutorial

In the next tutorial, we will discuss file saving, which describes how to save data back using DataFrames.