How to Load the Wine Dataset in Python with scikit-learn
The wine dataset is a small classification dataset with more columns than iris: 178 wines, 13 chemical measurements each, and three classes of wine. It ships with scikit-learn and loads with load_wine. This guide loads it and counts the classes, with real output from scikit-learn 1.9.1.
Syntax
from sklearn.datasets import load_wine
<dataset> = load_wine(as_frame=True)
X, y = load_wine(return_X_y=True, as_frame=True)
| Part | What it means |
|---|---|
as_frame=True | Returns pandas objects instead of NumPy arrays |
<dataset>.frame | One DataFrame: 13 measurements and a target column |
return_X_y=True | Returns just the measurements and the class codes |
The scikit-learn reference: "Load and return the wine dataset (classification)." And: "The wine dataset is a classic and very easy multi-class classification dataset."
Prerequisites
- scikit-learn and pandas in your project, for example with
uv add scikit-learn pandas. This guide uses scikit-learn 1.9.1 and pandas 3.1.1 on Python 3.15.2.
Step 1: Write the Script
from sklearn.datasets import load_wine
wine = load_wine(as_frame=True)
print(wine.frame.shape)
print(wine.target_names.tolist())
print(wine.frame["target"].value_counts().sort_index().to_dict())
print(wine.feature_names[:4])

Step 2: Run It
uv run python load_wine_demo.py
(178, 14)
['class_0', 'class_1', 'class_2']
{0: 59, 1: 71, 2: 48}
['alcohol', 'malic_acid', 'ash', 'alcalinity_of_ash']

- 178 rows, 14 columns: 13 measurements and the
target. - Three classes, not equal in size: 59, 71 and 48 wines.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Training a distance- or gradient-based model on the raw columns | The columns sit on very different scales: proline ran from 278.0 to 1680.0, hue from 0.48 to 1.71 | Scale them first, for example with StandardScaler |
| Splitting without keeping the class balance | A small test set's classes drift from the data's: a 10% split gave {0: 7, 1: 7, 2: 4} | stratify=y gave {0: 6, 1: 7, 2: 5}, close to the 59 : 71 : 48 of the whole set |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
wine.frame is None | Loaded without as_frame=True, as with the other loaders | Load it again with as_frame=True |
FAQ
What do the classes mean?
The toy dataset description: "The data is the results of a chemical analysis of wines grown in the same region in Italy by three different cultivators." The classes are those three, named only class_0, class_1 and class_2.
How do I get X and y?
X, y = load_wine(return_X_y=True, as_frame=True): a DataFrame of the 13 measurements and a Series of class codes.
Conclusion
load_wine(as_frame=True) loaded 178 wines with 13 measurements and three classes of 59, 71 and 48 wines. Scale the columns before models that care about scale.
Additional Resources
- load_wine — the function and its options.
- Toy datasets — the wine dataset's description.
