Importing Libraries and Loading the Dataset
Step 1: Install and import the libraries
If the libraries are not installed yet, install them once from the terminal (or a notebook cell starting with !):
pip install pandas numpy matplotlib seaborn scipy scikit-learn
Now import them in your notebook:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings("ignore")
sns.set_style("darkgrid")
pd,np,plt,snsare the standard short names used by almost every data scientist.warnings.filterwarnings("ignore")hides harmless warnings so the output stays readable. Use it carefully; in a real project it is better to read the warnings first.sns.set_style("darkgrid")gives every later plot a clean grid background.
Step 2: About the dataset
We use the WineQT dataset (red wine quality). Each row is one wine and each column is a laboratory measurement.
| Column | Meaning |
|---|---|
| fixed acidity, volatile acidity, citric acid | Different acids in the wine |
| residual sugar | Sugar left after fermentation |
| chlorides | Salt content |
| free / total sulfur dioxide | Preservative levels |
| density | Density of the wine |
| pH | Acidity level |
| sulphates | Wine additive |
| alcohol | Alcohol percentage |
| quality | Score given by tasters (target variable) |
| Id | A row identifier (not useful for analysis) |
Step 3: Read the CSV file
df = pd.read_csv("WineQT.csv")
print(df.head())
pd.read_csv() reads a comma-separated file into a DataFrame. Useful options:
| Option | Use |
|---|---|
sep=";" | when the delimiter is not a comma |
usecols=[...] | load only some columns |
nrows=1000 | load only the first 1000 rows (good for huge files) |
index_col="Id" | use a column as the row index |
na_values=["?", "NA"] | treat these strings as missing |
encoding="utf-8" | fix text-encoding errors |
df.head() shows the first five rows. Use df.head(10), df.tail() or df.sample(5) to see more.
Common mistakes
- Wrong file path - use
os.getcwd()to check the current folder. - Reading Excel files with
read_csv- usepd.read_excel()instead. - Forgetting that the first look at data can be misleading; a random
sample()is often more honest thanhead()because files are often sorted.