Lesson goal: Introduction to data files

Previous: Make an (x,y) plot | Home | Next: Reading data from a file

With the Internet, mobile phones, and sensors, we live in the age of information, or "data." Data science encompasses the idea that decisions and discoveries can be made by mining (or looking deeply into) into all of this data. In this lesson (and the ones that follow), we'll show you how to mine into data using your coding skills.

If you are working in data science, you must have access to the data somehow. Often it'll be stored in a database, or in a data file that you can access. This lesson will introduce you to the idea of a data file, and how to access it, in order to look at the numbers (or "data"), it contains. We'll try to discover some things about the data along the way.

To start, a data file on a computer has a name. Here we'll use a file called "sample.dat." To begin using the file, you have to "open it first." Here, data files are open for use using the file_open function.
Move the mouse over a dotted box for more information.

When you open a file using file_open, the computer will go out and see if the file exists, and that you have permission to use it. If all is OK, file_open will return a valid file handle. A valid file handle will contain a number like 0, 1, 2, 3... If the file is not available, file_open will return a -1, as an "error" condition.

Now you try. Run the code and see if the file sample.dat can be opened.

Type your code here:

See your results here: