Exploratory Data Analysis (Eda) With Python

Exploratory Data Analysis (EDA) with Python

In this article, we will explore a fundamental component of data science: Exploratory Data Analysis (EDA). Whether you are a Python beginner or an experienced enthusiast, this article caters to all. We ensure the accuracy of our content by exemplifying practical examples and citing credible sources. Let’s dive in.


Exploratory Data Analysis (Eda) With Python
Exploratory Data Analysis (Eda) With Python

Contents

  1. Understanding EDA
  2. Importance of EDA
  3. EDA Techniques
  4. Conducting EDA with Python
  5. Conclusion

1. Understanding EDA

Exploratory Data Analysis (EDA) is an approach developed by the esteemed statistician John Tukey in the 1970s. EDA allows data scientists to make sense of information by discovering patterns, spotting anomalies, testing hypotheses, and checking assumptions using visual methods, statistics, and other techniques.

In essence, EDA is about understanding the interesting aspects of data by using a variety of different methods to visualize their attributes. Before diving into EDA techniques, let’s comprehend its value.


2. Importance of EDA

  1. Data Cleaning: EDA helps in identifying and handling missing values, removing outliers, smoothing noisy data, and resolving inconsistencies, ensuring data quality.

  2. Model Selection: It aids in selecting the right model that will offer the best performance for your data.

  3. Feature Engineering: EDA may inspire the creation of new features that will better represent the underlying structure of the data.

  4. Assumptions Verification: Models are developed based on certain assumptions. EDA helps in validating these assumptions.

  5. Preparation for Modelling: EDA provides an excellent opportunity to pre-process data in a way that is most suitable for modelling.


3. EDA Techniques

EDA primarily uses the following techniques:

  1. Univariate Visualization: Examines each variable in your dataset separately.

    • For numerical variables(Histogram, Box Plot, etc.).
    • For categorical variables(Bar charts, Pie charts, etc.).

2.Bivariate Visualization: Examines the relationship between two variables.

- Numeric & Numeric (Scatter plot, Line plot, etc.).
- Categorical & Categorical (Stacked Column Chart, Chi-square test, etc.).
- Numeric & Categorical (Box plot, T-test, Z-test, ANOVA, etc.).

3.Multivariate Visualization: Examines the relationship between more than two variables simultaneously.


4. Conducting EDA with Python

Python offers robust libraries for EDA, namely, Pandas, Matplotlib, and Seaborn. Let’s walkthrough step-by-step how to conduct EDA using Python.

Import Libraries

import pandas as pd  # for data manipulation
import matplotlib.pyplot as plt  # for data visualization
import seaborn as sns  # for interactive visualization

Load Data

Let’s load a classic dataset for EDA, the “Iris” dataset:

# Load the data
df = pd.read_csv('Iris.csv')

Basic Analysis

We can use the head(), info(), describe(), and shape methods.

# top 5 records
df.head()

# information about a DataFrame 
df.info()

# statistical summary
df.describe()

# total number of rows and columns
df.shape

Missing Values

Check for missing values in the dataset.

df.isnull().sum()

Univariate Analysis

Let’s plot a histogram for the “SepalWidthCm” feature.

df['SepalWidthCm'].hist(bins=10)
plt.show()

Bivariate Analysis

Let’s check the relationship between “SepalLengthCm” and “PetalLengthCm” using a scatter plot.

df.plot.scatter(x='SepalLengthCm', y='PetalLengthCm', title='Scatter plot: SepalLengthCm vs PetalLengthCm')
plt.show()

Multivariate Analysis

Let’s represent multiple variables on the same plot using Seaborn’s pairplot function.

# pairplot
sns.pairplot(df.drop("Id", axis=1), hue="Species")
plt.show()

5. Conclusion

Exploratory Data Analysis is a crucial step before diving in deep into machine learning or statistical modeling. Although EDA can be time-consuming and repetitive, it provides a valuable foundation for the subsequent steps.

Python, with its robust tools and libraries, has made it simpler and user-friendly to conduct EDA. Understanding the data, detecting patterns, and checking underlying assumptions are some of the many tasks Python can handle with ease during EDA.

As John Tukey said, “EDA can never be the whole story, but certainly nothing else can serve as the foundation stone.” Happy Exploring!


Remember, exploratory data analysis is an iterative process: ask questions, find answers, then ask more in-depth questions! Keep practicing, improving your skills, and exploring data. It’s both a science and an art. Happy Python coding!

Do you have a favorite technique or a unique way of conducting EDA? Please share your thoughts in the comments below!

References:

  1. Data Science Handbook by Jake Vanderplas.
  2. Python Data Science Handbook: Essential Tools for Working with Data, O’Reilly Media.
  3. Statistics for Machine Learning by Pratap Dangeti.
  4. Matplotlib: Visualization with Python.
  5. Seaborn: Statistical Data Visualization.
Share this article:

Leave a Comment