Get the Iris dataset as CSV
How to get the Iris flower dataset as a CSV file, what changes when you convert it between formats, and how to check that the result is still accurate and usable.
The Iris flower dataset is one of the most widely reused tables in statistics and machine learning. It records four measurements for each flower: sepal length, sepal width, petal length and petal width, in centimetres. Each row also carries a species label. The standard version has 150 rows, with 50 rows for each of three species: setosa, versicolor and virginica. Because the table is small, numeric and rectangular, CSV is a natural format for it. Getting a CSV copy that matches what your code or spreadsheet expects still involves a few decisions. This article explains them.
Is a CSV copy suitable for your use?
For most purposes, yes. The main benefit of CSV is portability. Spreadsheets, statistics packages, databases and almost every programming language can read a comma-separated file without extra libraries, and a person can read the file in a plain text editor. The main tradeoff is that CSV stores only text. It carries no column types, no units and no record of where the data came from. The fact that the last column is a categorical label rather than free text has to be inferred by whatever reads the file.
There are situations where plain CSV is not the best choice. If you work entirely in R or Python, the built-in loaders already give you a typed table, and exporting to CSV adds a step that can only lose information. If you need to share the data with someone whose spreadsheet uses a comma as the decimal separator, tab-separated text often avoids misreadings. If you need to cite a specific version of the data, keep the original distribution file alongside any converted copy. Your own export is not an authoritative source.
Where the CSV usually comes from
Several common sources produce slightly different files. None of them is wrong. They differ in column names, label wording, whether a header row is present, and how numbers are written. Pick the one that matches the tool you will use next.
| Source | Header row | Species labels | Notes |
| UCI Machine Learning Repository data file | None in the original file | Prefixed, such as Iris-setosa | Comma-separated; you must add column names yourself; check for an empty final line |
| R built-in iris data frame | Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Species | setosa, versicolor, virginica | Available offline; write.csv quotes text and header fields by default |
| scikit-learn load_iris | Names such as sepal length (cm) | Stored as integer codes 0, 1, 2 plus a separate list of names | Available offline once installed; map the codes to names if you want readable labels |
| seaborn load_dataset | sepal_length style names | setosa, versicolor, virginica | Downloads the file on first use, so it needs a network connection |
There is also a documented caveat about the data itself. Some widely circulated copies differ from the values in Fisher's original 1936 paper in a small number of entries. If exact agreement with the original publication matters, for example when reproducing a published result, compare your copy against the source the original study used. Do not assume that all copies are identical.
Exporting from R or Python
In R, the dataset ships with the base installation. Setting row.names to FALSE stops R from adding an unnamed first column of row numbers:
write.csv(iris, "iris.csv", row.names = FALSE)
In Python with scikit-learn and pandas, the loader returns integer class codes. This snippet replaces them with species names before saving, and drops the pandas index for the same reason as in R:
import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris(as_frame=True)
df = iris.data.copy()
df["species"] = pd.Categorical.from_codes(iris.target, iris.target_names)
df.to_csv("iris.csv", index=False)
What a conversion actually changes
In this context, the word "transformation" means changing how the same table is written down. It does not mean reversing, mirroring or restyling characters. When you export Iris to CSV, or convert between CSV and TSV, the stored characters do change: delimiters, quotation marks, header names and number formatting can all differ. The measurements and labels should not change. Separate these two layers when you judge whether a conversion is safe.
Here is an example. The first rows of the R version, saved with write.csv, look like this:
"Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
5.1,3.5,1.4,0.2,"setosa"
4.9,3,1.4,0.2,"setosa"
4.7,3.2,1.3,0.2,"setosa"
The same rows from a pandas export without quoting would be written as 4.9,3.0,1.4,0.2,setosa. The quotes around setosa and the difference between 3 and 3.0 are differences in how the values are written. A CSV parser reads both files as the same values. A plain text comparison or a checksum, however, will report them as different files. Do not treat that as evidence that the data changed.
Converting from TSV to CSV, or the reverse, should only swap the delimiter and apply whatever quoting the target format needs. Use a real CSV library rather than search-and-replace. A library handles quoting correctly, and search-and-replace does not. This Python example uses only the standard library:
import csv
with open("iris.tsv", newline="") as src, open("iris.csv", "w", newline="") as dst:
csv.writer(dst).writerows(csv.reader(src, delimiter="\t"))
Iris contains no commas, tabs, line breaks or non-ASCII characters inside its fields. Encoding and embedded delimiters are therefore not a practical concern for this dataset, although they would be for messier text data.
Checks to run after conversion
- Row count: 150 data rows, plus one header row if you added one.
- Column count: five columns on every row, with no extra unnamed index column.
- Class balance: 50 rows for each species.
- Labels: one consistent naming scheme, either setosa or Iris-setosa, not a mix of the two.
- Numbers: all four measurement columns parse as numbers, with a full stop as the decimal separator.
- Trailing lines: no empty final row that a reader might count as a record.
Will it stay readable after copying or sharing?
A CSV file is plain text, so copying it between text editors, terminals and code repositories preserves it exactly. Problems tend to appear when a spreadsheet application opens or imports the file. Spreadsheets guess delimiters and data types, and they apply regional settings. In locales that use a comma as the decimal mark, a comma-separated file of decimal numbers can be split or interpreted incorrectly. Pasting rows copied from a web page into a spreadsheet may also be parsed differently from opening a saved file. No tests of specific spreadsheet products or versions were available for this article. Check the result in the application you actually use rather than assuming it will behave correctly.
Accessibility depends mostly on how the data is presented, not on the file format. A raw CSV read aloud by a screen reader is a stream of numbers and commas with no column context. If people will read the data rather than process it, present it as a properly marked-up table with header cells, or in a spreadsheet with a header row. No documentation or testing of particular assistive technologies was available here, so check the presentation with the tools your readers use.
Search and editing are not a concern for a file this simple. The text remains ordinary characters that can be searched, compared and edited. If you publish the file, also state its source, its column units (centimetres) and which label scheme you used. CSV has no place to record that information inside the file.
Gaps in this overview
No evidence was supplied about specific online converters or download services, including their privacy or data-retention practices. Because Iris is public data, privacy matters less here than it would for your own data. Even so, it is safer to export the dataset locally with R or Python than to rely on an unverified third-party tool. The exact entries that differ between circulating copies and the original paper are not listed here. Consult the documentation of your chosen source if you need them.