Bird
Raised Fist0
Data Analysis Pythondata~5 mins

Exploratory Data Analysis (EDA) template in Data Analysis Python

Choose your learning style10 modes available
Introduction

Exploratory Data Analysis helps us understand data by summarizing and visualizing it. It shows patterns, errors, and important features before deeper analysis.

When you get a new dataset and want to know what it contains.
Before building a model to check data quality and relationships.
To find missing or strange values in your data.
To compare groups or categories in your data.
To decide which features are important for your analysis.
Syntax
Data Analysis Python
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

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

# Basic info
print(df.info())
print(df.describe())

# Check missing values
print(df.isnull().sum())

# Visualize distributions
sns.histplot(df['column'])
plt.show()

# Visualize relationships
sns.scatterplot(x='col1', y='col2', data=df)
plt.show()

Use pandas for data handling and seaborn/matplotlib for plots.

Replace 'df' and column names with your actual data names.

Examples
Shows the first 5 rows to get a quick look at the data.
Data Analysis Python
print(df.head())
Gives summary statistics like mean, min, max for numeric columns.
Data Analysis Python
print(df.describe())
Shows distribution and outliers of 'value' for each 'category'.
Data Analysis Python
sns.boxplot(x='category', y='value', data=df)
plt.show()
Displays correlation between numeric columns to find relationships.
Data Analysis Python
sns.heatmap(df.corr(), annot=True)
plt.show()
Sample Program

This code loads a small dataset, shows basic info and stats, checks for missing data, and creates three plots: age distribution, salary by department, and correlation matrix.

Data Analysis Python
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Sample data
data = {
    'Age': [25, 30, 22, 40, 28, 35, 23, 31],
    'Salary': [50000, 60000, 45000, 80000, 52000, 75000, 48000, 62000],
    'Department': ['HR', 'IT', 'HR', 'IT', 'Finance', 'Finance', 'HR', 'IT']
}

# Create DataFrame
df = pd.DataFrame(data)

# Basic info
print(df.info())

# Summary statistics
print(df.describe())

# Check missing values
print(df.isnull().sum())

# Distribution of Age
sns.histplot(df['Age'], bins=5)
plt.title('Age Distribution')
plt.show()

# Boxplot Salary by Department
sns.boxplot(x='Department', y='Salary', data=df)
plt.title('Salary by Department')
plt.show()

# Correlation heatmap
sns.heatmap(df.corr(), annot=True)
plt.title('Correlation Matrix')
plt.show()
OutputSuccess
Important Notes

Always check for missing values before analysis.

Visualizations help spot patterns and outliers easily.

Use small samples first to understand data before big computations.

Summary

EDA helps you understand data quickly and clearly.

Use simple commands to get info, stats, and visuals.

Check data quality and relationships before deeper analysis.

Practice

(1/5)
1. What is the main purpose of Exploratory Data Analysis (EDA) in data science?
easy
A. To build machine learning models directly
B. To clean data without checking it
C. To understand the data quickly and find patterns
D. To create final reports without analysis

Solution

  1. Step 1: Understand EDA's role

    EDA is used to explore and understand data before any modeling or cleaning.
  2. Step 2: Compare options

    Only To understand the data quickly and find patterns correctly states EDA's purpose as understanding data quickly and finding patterns.
  3. Final Answer:

    To understand the data quickly and find patterns -> Option C
  4. Quick Check:

    EDA = Understand data fast [OK]
Hint: EDA means exploring data first, not modeling [OK]
Common Mistakes:
  • Confusing EDA with model building
  • Thinking EDA skips data checking
  • Assuming EDA creates final reports
2. Which Python command is commonly used to get a quick summary of a DataFrame's structure during EDA?
easy
A. df.describe()
B. df.info()
C. df.plot()
D. df.head()

Solution

  1. Step 1: Recall DataFrame methods

    df.info() shows data types, non-null counts, and memory usage.
  2. Step 2: Compare with other methods

    df.describe() gives stats, df.plot() makes graphs, df.head() shows rows. Only df.info() summarizes structure.
  3. Final Answer:

    df.info() -> Option B
  4. Quick Check:

    DataFrame structure = df.info() [OK]
Hint: Use df.info() for quick data structure summary [OK]
Common Mistakes:
  • Using df.describe() for structure instead of stats
  • Confusing df.head() with info summary
  • Trying to plot before understanding data
3. Given the code:
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 2, 3], 'B': [4, 5, 6, 7]})
print(df['A'].value_counts())

What is the output?
medium
A. 2 2 1 1 3 1 Name: A, dtype: int64
B. 1 2 2 1 3 1 Name: A, dtype: int64
C. 4 1 5 1 6 1 7 1 Name: B, dtype: int64
D. Error: value_counts() not found

Solution

  1. Step 1: Understand value_counts()

    It counts how many times each unique value appears in the column.
  2. Step 2: Count values in column 'A'

    Values are 1 (once), 2 (twice), 3 (once). value_counts() sorts by frequency descending, so: 2 2 1 1 3 1 Name: A, dtype: int64
  3. Final Answer:

    2 2 1 1 3 1 Name: A, dtype: int64 -> Option A
  4. Quick Check:

    Count unique values = 2 2 1 1 3 1 Name: A, dtype: int64 [OK]
Hint: value_counts() counts unique values in a column [OK]
Common Mistakes:
  • Mixing counts of column B instead of A
  • Misreading counts order
  • Expecting error from value_counts()
4. You run this code:
import pandas as pd
df = pd.DataFrame({'X': [1, 2, None, 4], 'Y': [5, None, 7, 8]})
print(df.describe())

But the output misses some rows. What is the likely problem?
medium
A. describe() excludes rows with missing values by default
B. describe() ignores non-numeric columns
C. DataFrame has no numeric columns
D. Syntax error in code

Solution

  1. Step 1: Understand describe() behavior

    describe() calculates stats on numeric columns but skips missing values in calculations.
  2. Step 2: Check missing data effect

    Rows with None are ignored in count and stats, so output shows fewer rows counted.
  3. Final Answer:

    describe() excludes rows with missing values by default -> Option A
  4. Quick Check:

    Missing data skipped in describe() = describe() excludes rows with missing values by default [OK]
Hint: describe() skips missing values in stats by default [OK]
Common Mistakes:
  • Thinking describe() drops entire rows
  • Assuming syntax error causes missing rows
  • Believing describe() works only on non-numeric data
5. You have a DataFrame df with columns age, income, and gender. You want to quickly check if income differs by gender. Which EDA step is best?
hard
A. Plot df['age'] histogram
B. Use df.describe() only
C. Drop missing values without checking
D. Use df.groupby('gender')['income'].mean() to compare averages

Solution

  1. Step 1: Identify goal

    You want to compare income by gender groups.
  2. Step 2: Choose correct EDA method

    Grouping by gender and calculating mean income shows differences clearly.
  3. Final Answer:

    Use df.groupby('gender')['income'].mean() to compare averages -> Option D
  4. Quick Check:

    Group and average to compare = Use df.groupby('gender')['income'].mean() to compare averages [OK]
Hint: Group by category and calculate mean to compare groups [OK]
Common Mistakes:
  • Using describe() without grouping
  • Plotting unrelated columns
  • Dropping data before checking
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard