Exploratory Data Analysis Ultimate Guide
Tags: analytics, datascience
Published: 2023-03-02 10:57:24

The phrase "Data is the new gold", emphasizes the increasing value of data in today's world. When properly analyzed, data can uncover valuable insights that inform critical decisions and shape the future. In order to extract insights from data, one must first understand it. This is where Exploratory Data Analysis (EDA) comes in. 

## **1. What is Exploratory Data Analysis?**
Exploratory data analysis is one of the first steps in the data analytics process. It entails application of various techniques in analysis of the dataset in order to understand the data.

Understanding the dataset simply means to getting to know the data and its characteristics, which can help in identifying potential issues, patterns, and relationships within the data.

## **2. What is the objective of Exploratory Data Analysis?**
There are two main objectives of EDA:

- EDA assists in identifying faulty points in the data. Once the faulty points have been identified, they can be easily removed, resulting in data cleaning.

- It also helps in understanding the relationship between the variables. This gives a wider perspective on the data which helps  in building models by utilizing the relationship between various features(variables).

## **3.Types of Exploratory Data Analysis**
There are two main types of exploratory data analysis which are Univariate EDA and Multivariate EDA.

### Univariate EDA
Uni means one and variate means variable, so in Univariate Analysis there is only one dependable variable. The goal of univariate analysis is to simply describe the data and find patterns with the data. Univariate EDA techniques include:

#### _Univariate non-graphical EDA techniques:_

- Central Tendency (mean, mode and median)
- Dispersion (range, variance)
- Quartiles (interquartile range) 
- Standard deviation.

#### _Univariate graphical EDA techniques:_
These are graphical methods that provide a visualization of the data. Common types of univariate graphics include:

- **Histograms**, a graph plot in which each bar represents the frequency distribution of numerical data.

- **Box plots**, which graphically depict the five-number summary of minimum, first quartile, median, third quartile and maximum.


### Multivariate EDA
This is a method of analyzing data involving more than two variables. The goal is to understand patterns, correlations and interactions between variables. Multivariate techniques include:

#### _Multivariate non-graphical EDA techniques:_
These techniques generally show the relationship between two or more variables of the data through cross-tabulation or statistics.

#### _Multivariate graphical EDA techniques:_
These are graphical methods that display the relationships between two or more sets of data. Common types of multivariate graphics include:

- **Scatter plot**, it is used to plot two quantitative variables on a horizontal (x-axis) and vertical(y-axis) to display the relationship between the continuous variables.

- **Multivariate chart**, is a graphical representation of the relationships between factors and a response.

- **Run chart**, a line graph drawn over time. It visually illustrates the data values in a time sequence.

- **Bubble chart**, scatter plots that display multiple circles (bubbles) in a two-dimensional plot.

- **Heatmap**, a graphical representation of data in the form of a map or diagram in which data values are represented as colors.


## **4. Exploratory Data Analysis Tools**

#### Python
Python is used for different tasks in EDA, such as finding missing values in data collection, data description, handling outliers, obtaining insights through charts etc.

#### R
R programming language is a regularly used option to make statistical observations and analyze data, i.e., perform detailed EDA by data scientists and statisticians.

#### MATLAB
It is common among engineers and domain experts due to its strong mathematical calculation ability.


## **5. Steps involved in Exploratory Data Analysis**
There are three main steps involved in exploratory data analysis. They can be simplified as data collection, data cleaning and analysis of the relationship between the variables.

### 1. Data Collection
It is the first step in EDA, it involves gathering relevant data from various sources. Some reliable sites for data collection are Kaggle, GitHub, UCI Machine Learning Repository etc.

The data depicted in the example represents the 120 years of Olympic History dataset that is available on Kaggle.

While at the IDE of choice, start by importing the necessary libraries.
![Importing necessary Libraries](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iy1lfu03u29bvva4jvfs.png)
Then, load the dataset into DataFrames:
![Loading dataset](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q1itvrihmrfcu1bmhtvx.png
)
Display the content of the datasets:
![Main df](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zyqs4j6lqhmq5j7d0s2.png)
Regions dataset:
![Regions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bj7h0vy2mfv3himh8s2f.png)
Check the shape of the DataFrames:
![df.shape](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a69vdo4gm35bm3tcc88n.png)
This DataFrame shape is (271116, 15) which means that it has 271116 observations (rows) and 15 features (columns).
Checking the region's DataFrame shape:
![region](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v7vb4xcda08r7hlck3ha.png)
The DataFrame shape is (230, 3) which implies that it has 230 rows and 3 columns.
Next, Merge the two DataFrames:
![Olympics df](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1vjkqodaczc27lcbt23.png)
Check the shape of the Olympics DataFrame:
![Olympics shape](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ey40nuv23vgkmr6z531z.png)
Display the content of the Olympics DataFrame:
![olympics.head()](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qm8lrdlhwjdwemaasy82.png)
Check the concise summary of the DataFrame using the info() function.
![information](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0g0736ctpphtap1m1gfm.png)
Check the descriptive analysis of the DataFrame using the describe() function. It provides descriptive information about the dataset.
![descriptive analysis](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7oyq8fqjs8iy0znxx7bo.png)

### 2. Data Cleaning
This is a critical step in EDA that involves identifying and correcting errors and inconsistencies in the data to ensure its accuracy and integrity.

#### **1. _Handling the missing values._**
This is a crucial step in data analysis. Missing values can be handled in various ways:

1. _Removing missing values_ - this is simply removing any rows or columns that contain missing values. This is only appropriate if the amount of missing data is small relative to the size of the dataset and removing the missing data does not significantly affect the analysis.

2. _Imputing missing values_ - this is imputing the missing value with an estimated value. The simplest approach is to impute the missing values with the mean, median, or mode of the non-missing values. More advanced imputation techniques involve using machine learning algorithms to predict the missing values based on other features in the dataset.

3. _Ignoring missing values_- in some cases, it may be appropriate to ignore missing values if they do not significantly affect the analysis.

**Handling missing values in the Olympics dataset:**

First check for missing values:
![missing values](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mzbaoxnf6hd3p0iksnv0.png)
Then, the percentage of missing values:
![Percentage of missing values](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9rwg3txou6n5ylh9sg9j.png)
The results above provide insights on how to handle the missing values in the Olympics dataset.

The Notes columns has 98% of the data missing and can therefore be dropped.
![drop column](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0mef1bs0cqcp1shr940.png)
The Height and Weight missing values can be be imputed by the mean.
![impute missing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpzaepj84tqv297g77fk.png)
The Age column has 3% of the data missing, while Region has 0.3%, this value is relatively small and thus any modification to the column can be ignored. The missing values in the Medal column are ignored since Nan indicates that no medals were won.

#### **2. _Handling duplicate values._**
This involves identifying and removing or modifying duplicates. Here are some common approaches of handling duplicate values:

1. _Identifying and removing exact duplicates_- Exact duplicates are rows that have identical values in all columns.

2. _Identifying and removing partial duplicates_- Partial duplicates are rows that have the same values in some columns but differ in others.

Here's a code example of how to handle the duplicates mentioned above:
![duplicates](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x4on58hjwrvhwypia7gw.png)
The Olympics dataset does not require this check because duplicates are inevitable given the nature of the data.

### 3. Analyzing the relationship between the variables.

####**_Univariate non-graphical EDA_**
**Top 10 participating countries**
![Top 10 participating countries](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ksbtm1k84aoxxk9mba9a.png)

#### _**Univariate graphical EDA**_
**Bar plot for Top 10 participating countries**
![barplot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/704dxys7c9eror8rqez0.png)
code:
![code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2enz7r5brqfmvkkp1913.png)

**Age distribution of the athletes**
![Age distribution of the athletes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rryidjxo3xwwk71njlvy.png)
code:
![code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25988djsjv2zmy043492.png)
Interpretation: Most participants were aged between 23-26 years.

**Height distribution of the athletes**
![height](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wf16tfsmh675yp9b38pw.png)
Code:
![code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8lvelq3rkpfyaicnzaq.png)
Interpretation: The height of the athletes ranges between 150cm to 178cm. Most of the participants had a height of 175cm


#### **_Multivariate non-graphical EDA_**
**Number of athletes in respect to their gender**
![Gender](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4n7eczvbqn9jd1jc7nb.png)

**Top 15 Countries and number of Gold Medals Won in the 2016 Olympics**
![top 15](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/myp27m47mwvhffuy56zn.png)

#### **_Multivariate graphical EDA_**
**Pie plot for male and female distribution of athletes**
![Pie Plot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3k5px0sbyzvbvllatf9.png)
Code:
![code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7hh9rrgn7781amxggyis.png)

**Line Plot of Female Athletes over time**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzlajws6rvalt9gg0ems.png)
Code:
![code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iykpynizsknutthl0a0r.png)
**Bar-plot for Top 15 Countries and number of Gold Medals Won in the 2016 Olympics**
![top 15](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vf8rust93gt9lwc0hztt.png)
Code:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7e4yggzaytrcy7kz8ufo.png)
## Conclusion
It is crucial to keep in mind that EDA is an iterative process and that the steps used can change based on the  dataset and the objectives of the analysis. In addition, domain knowledge and context are important factors in understanding and drawing meaningful insights from the data.