Loading a dataset from a file

This tutorial tells use the DataFrame to load a file

Loading from a File

By far the easiest way to load a file into a DataFrame is to load it from a comma separated file (CSV). Recall that a CSV is a plain text file that contains data, with commas separating each cell in the table.This is the default setting in DataFrames and calling Load automatically detects these file types. Here is a brief explanation of what our Load(text filepath) function does.

Load Helper Function
FunctionDescriptionUsage
frame:Load(text filepath)This function takes in a string which is the location of the file path (inside the file explorer) of the dataset we want to read in.frame:Load("../Data/Food/FastFoodRestaurants.CSV")

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 use the Load(text filepath) method in order for our data frame to properly locate and read in our dataset. Then, to confirm if we read all of our data, we can actually output all the contents on the terminal

We should have the following code:

Code Example

//We need the DataFrame class to load in files for Data Science operations.
use Libraries.Compute.Statistics.DataFrame

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

//This loads data relative to the project, so put the Population.csv file in the Data folder
//If we deploy our program, this path is relative to the binary.
frame:Load("../Data/Geography/US States.csv")

//The system loaded the file, but can also output it a text value, or the console, if we want that.
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!"

Next Tutorial

In the next tutorial, we will discuss data loading, which describes how to load data "by Hand" in a file using DataFrames.