A data set is a collection of related data that is kept together for a purpose, such as analysis, reporting or training a model. Most data sets are tables: each row is one record, and each column is one attribute of those records.
The word is used loosely, so it helps to pin down what it does and does not mean. This article gives the definition, a small worked example, the file formats data sets usually come in, and how a data set differs from a database and from a data structure.
What is a data set, exactly?
There is no single programming definition, but the W3C gives a precise one for data catalogs. Its Data Catalog Vocabulary (DCAT, version 3) defines a dataset as a collection of data, published or curated by a single agent or identifiable community. The same document says a dataset is a conceptual entity: it can be made available in one or more serializations or formats, which DCAT calls distributions.
That last point matters in practice. The same data set might be offered as a CSV download, a JSON file and an API. They are three distributions of one data set, not three data sets.
Two parts make a collection of data a data set rather than a pile of files:
- The items belong together. They describe the same kind of thing, for example every order a shop received in October.
- There is a shared structure or description. Every record has the same fields, or someone has written down what the fields mean.
You will see both "data set" and "dataset". They mean the same thing. DCAT uses the one-word form; this article uses two words in prose because that is how the search phrase is usually written.
A small data set, row by row
Here is a complete, tiny data set about orders. The made-up values are for illustration only.
| order_id | customer | item | quantity | unit_price_eur |
|---|---|---|---|---|
| 1001 | Ana | notebook | 3 | 2.50 |
| 1002 | Ben | pen | 10 | 0.80 |
| 1003 | Ana | stapler | 1 | 6.00 |
The terms for its parts vary by field, which is a common source of confusion:
| Part | Database term | Statistics term | Machine learning term |
|---|---|---|---|
| One row | record, tuple | observation | instance, example |
| One column | field, column | variable | feature |
| The whole table | table | data set | data set |
This one has 3 rows and 5 columns. Real data sets range from a few rows to billions, but the shape is the same.
How to read a data set in Python
As a file, the table above is a CSV. The Python documentation describes CSV (Comma Separated Values) as the most common import and export format for spreadsheets and databases. Saved as orders.csv, it looks like this:
order_id,customer,item,quantity,unit_price_eur
1001,Ana,notebook,3,2.50
1002,Ben,pen,10,0.80
1003,Ana,stapler,1,6.00
The standard library's csv.DictReader reads each row as a dictionary. When you do not pass fieldnames, it uses the first row of the file as the keys and leaves that row out of the results:
import csv
with open("orders.csv", newline="") as csv_file:
for row in csv.DictReader(csv_file):
print(row["customer"], row["item"], row["quantity"])
Example output:
Ana notebook 3
Ben pen 10
Ana stapler 1
Every value arrives as a string. A CSV file does not record that quantity is a number, so you convert it yourself, for example with int(row["quantity"]). That gap is why data sets are often shipped with a description of their columns. For a full treatment of that description, see what a data dictionary is.
Common data set formats
The format is how the data is written to a file. The data set itself is the content.
| Format | Shape | Good for | Limit to know |
|---|---|---|---|
| CSV | Flat rows and columns, plain text | Spreadsheets, quick exchange between tools | No data types; every value is text |
| JSON | Nested objects and arrays | API responses, records with variable fields | Repeats field names in every record, so files are larger |
| SQL database export | Several related tables | Data with relationships between tables | Needs a database to query it |
| Image, audio or text folders | One file per item, plus labels | Training and testing machine learning models | Labels live in a separate file or folder name |
If you need to turn one of these into another, the JSON to CSV converter runs in your browser.
What does a data set need besides the data?
A file of numbers is hard to use without context. Good data sets travel with a description. The Frictionless Data Package specification is one concrete example. It defines a Data Package as a simple container format for describing a coherent collection of data in a single package. The description lives in a file named datapackage.json in the top-level directory, and the specification requires it to contain a resources property listing the data files.
You do not have to use that standard. The useful habit is the one it encodes: say what the files are, what each column means, what units it uses and who is responsible for it. DCAT's wording, data "published or curated by a single agent", points the same way: somebody is accountable for the data.
Data set vs database vs data structure
These three terms are easy to mix up.
- Data set: a body of data, usually delivered as one or a few files. It is passive. You read it.
- Database: software that stores data, enforces rules and answers queries from many users. It can hold many data sets, and a query result can be exported as one.
- Data structure: a way of organizing values in a program's memory, such as a list or a dictionary. When you load a CSV with Python, you put the data set into data structures. The article on what a data structure is covers that side.
Common kinds of data sets
People usually name data sets by what they are used for:
- Tabular data sets: rows and columns, such as sales records or sensor readings.
- Time series: records ordered by time, such as hourly temperature.
- Text corpora: collections of documents, such as support tickets.
- Image or audio collections: media files, often with labels.
- Training, validation and test sets: in machine learning, one data set is commonly split into these parts, so a model is judged on records it has not seen during training.
Problems to check before you trust a data set
Before you analyze any data set, look for these:
- Missing values. In
csv.DictReader, a row with fewer fields than the header getsNonefor the missing ones by default (therestvalsetting). An empty cell, by contrast, arrives as an empty string. Decide how you will treat both. - Extra fields. A row with more values than headers stores the extras in a list under the
Nonekey by default (therestkeysetting). That usually means an unquoted comma in a text field. - Duplicates. Check that the identifier column, here
order_id, is unique. - Units and encodings. A column named
pricesays nothing about the currency. Read the documentation, or ask the publisher. - Licensing. Publicly downloadable does not mean free to reuse. Look for a license statement.
If you need sample records to test code and cannot use real ones, generate fake rows with the test data generator instead of copying real customer data into a test file.
Frequently asked questions
- Is it "data set" or "dataset"?
- Both spellings are used for the same thing. Standards such as W3C's DCAT write "dataset" as one word, and many style guides write "data set" as two. Pick one spelling and use it consistently in your own documents.
- What is the difference between a data set and a database?
- A data set is a body of data collected for some purpose, often a single file or a few related files. A database is software that stores data and lets many users query and change it. A database can hold many data sets, and you can export a query result from a database as a data set.
- What are the rows and columns in a data set called?
- In a table-shaped data set, each row is usually called a record, observation or instance, and each column is called a field, variable or feature. The first row often holds the column names.
- Does a data set have to be a spreadsheet?
- No. Tabular data in rows and columns is the most common shape, but a data set can also be a set of images, a collection of text documents, audio files, or nested JSON records. What makes it a data set is that the items belong together and share a purpose.
- Where can I find free data sets to practice with?
- Government open-data portals and research repositories publish data sets with documented licenses. Check the license and the description of each data set before you use it, since reuse terms differ from one publisher to the next.