Exploratory data analysis helps us understand data by looking at it carefully. It shows patterns, problems, and important details before building models.
When you get a new dataset and want to know what it contains.
Before cleaning data to find missing or strange values.
To find relationships between different data points.
To decide which features are important for a model.
To check if data matches your expectations or needs fixing.
Syntax
ML Python
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Load data
data = pd.read_csv('data.csv')
# Show first rowsprint(data.head())
# Summary statisticsprint(data.describe())
# Check missing valuesprint(data.isnull().sum())
# Visualize data
sns.histplot(data['column'])
plt.show()
Use head() to see first few rows quickly.
describe() gives basic stats like mean and quartiles.
Examples
Shows the first 10 rows of the dataset to get a quick look.
ML Python
data.head(10)
Gives summary statistics for numeric columns like mean, min, max.
ML Python
data.describe()
Counts how many missing values are in each column.
ML Python
data.isnull().sum()
Draws a box plot to see data spread and outliers.
ML Python
sns.boxplot(x=data['column'])
plt.show()
Sample Model
This code creates a small dataset, shows its first rows, summary stats, missing values, and draws a histogram of ages.
ML Python
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Create a small sample dataset
data = pd.DataFrame({
'Age': [25, 30, 22, 40, 28, None, 35],
'Salary': [50000, 60000, 45000, 80000, 52000, 58000, None],
'Department': ['Sales', 'IT', 'Sales', 'HR', 'IT', 'HR', 'Sales']
})
# Show first rowsprint('First rows:')
print(data.head())
# Summary statisticsprint('\nSummary statistics:')
print(data.describe())
# Missing valuesprint('\nMissing values:')
print(data.isnull().sum())
# Visualize Age distribution
sns.histplot(data['Age'], kde=True)
plt.title('Age Distribution')
plt.show()
OutputSuccess
Important Notes
Always check for missing or strange values early.
Visualizations help see patterns that numbers alone may hide.
Use simple stats first before complex analysis.
Summary
Exploratory data analysis helps you understand your data clearly.
Look at data samples, summary stats, and missing values first.
Use charts to find patterns and problems easily.
Practice
(1/5)
1. What is the main goal of exploratory data analysis (EDA) in machine learning?
easy
A. To train the machine learning model
B. To understand the main features and quality of the data
C. To deploy the model to production
D. To write the final report without looking at data
Solution
Step 1: Understand the purpose of EDA
EDA is used to explore and understand the data before modeling.
Step 2: Differentiate EDA from other steps
Training and deployment happen after EDA, so they are not the main goal of EDA.
Final Answer:
To understand the main features and quality of the data -> Option B
Quick Check:
EDA = Understand data [OK]
Hint: EDA means exploring data, not modeling or deploying [OK]
Common Mistakes:
Confusing EDA with model training
Thinking EDA is for deployment
Skipping data understanding step
2. Which Python library is commonly used for basic exploratory data analysis tasks like viewing data samples and summary statistics?
easy
A. matplotlib
B. tensorflow
C. pandas
D. scikit-learn
Solution
Step 1: Identify libraries for EDA
Pandas provides functions like head() and describe() for data samples and summary stats.
Step 2: Exclude other libraries
Matplotlib is for plotting, scikit-learn for modeling, tensorflow for deep learning, not basic EDA.
Final Answer:
pandas -> Option C
Quick Check:
pandas = data samples and stats [OK]
Hint: Use pandas for quick data overview and stats [OK]
Common Mistakes:
Using matplotlib for data samples
Confusing modeling libraries with EDA
Trying tensorflow for simple stats
3. Given the following Python code using pandas, what will print(df.describe()) output?