devnotes.

Importing Libraries and Loading the Dataset

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, sns are 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.

ColumnMeaning
fixed acidity, volatile acidity, citric acidDifferent acids in the wine
residual sugarSugar left after fermentation
chloridesSalt content
free / total sulfur dioxidePreservative levels
densityDensity of the wine
pHAcidity level
sulphatesWine additive
alcoholAlcohol percentage
qualityScore given by tasters (target variable)
IdA 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:

OptionUse
sep=";"when the delimiter is not a comma
usecols=[...]load only some columns
nrows=1000load 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 - use pd.read_excel() instead.
  • Forgetting that the first look at data can be misleading; a random sample() is often more honest than head() because files are often sorted.
Importing Libraries and Loading the Dataset | Exploratory Data Analysis | DevNotes