Visualization & EDA (Exploratory Data Analysis)

Python tutorial · PySpark.in

Visualization & EDA (Exploratory Data Analysis)

Covering Pandas plotting, Histogram, Bar, Line, Box plots, and Pandas + Matplotlib / Seaborn

What is EDA?

EDA (Exploratory Data Analysis) means:

Understanding data using charts, plots, and statistics before applying ML models.

Purpose:

Sample Dataset

```

import pandas as pd

df = pd.DataFrame({

'City': ['Delhi', 'Mumbai', 'Chennai', 'Delhi', 'Mumbai'],

'Sales': [100, 150, 120, 130, 160],

'Year': [2021, 2021, 2021, 2022, 2022]

})

print(df)

```

Plotting with Pandas

Pandas has built-in plotting using Matplotlib internally.

Basic Syntax

```

hide

df.plot()

```

Example

```

df['Sales'].plot()

```

Creates a line plot by default

Why use Pandas plotting?

✔ Quick visualization
✔ Less code
✔ Good for EDA

Histogram

What is Histogram?

Why use it?

✔ Check data spread
✔ Detect skewness
✔ Identify outliers

```

df['Sales'].plot(kind='hist', bins=5)

```

Output Meaning

Used before normalization & scaling

Bar Plot 📉

What is Bar Plot?

Example

```

df.groupby('City')['Sales'].mean().plot(kind='bar')

```

Output Meaning

Best for:

Line Plot

What is Line Plot?

Example

```

df.groupby('Year')['Sales'].sum().plot(kind='line')

```

Output Meaning

Used for:

Box Plot 📦

What is Box Plot?

Components

```

df['Sales'].plot(kind='box')

```

Output Meaning

Very important for data cleaning

Pandas + Matplotlib / Seaborn

Pandas + Matplotlib

```

import matplotlib.pyplot as plt

df['Sales'].plot(kind='hist')

plt.title("Sales Distribution")

plt.xlabel("Sales")

plt.ylabel("Frequency")

plt.show()

```

✔ More control
✔ Labels, titles, colors

Pandas + Seaborn (Advanced & Beautiful)

```

import seaborn as sns

sns.boxplot(x='City', y='Sales', data=df)

```

✔ Cleaner plots
✔ Statistical visuals
✔ Widely used in ML projects

More Python tutorials

All tutorials · Try the free PySpark compiler · Practice challenges