0% found this document useful (0 votes)
2 views8 pages

Module3 Python For Data Analysis

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Module3 Python For Data Analysis

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module 3: Python for Data Analysis

Introduction to Data Analysis with Python

Python is one of the most popular languages for data analysis due to its readability, ecosystem, and
wide adoption in both academia and industry. This section introduces core libraries: pandas for data
manipulation, numpy for numerical operations, matplotlib and seaborn for visualization.
Working with Data in Pandas

The pandas library provides DataFrame and Series objects for structured data. Common operations
include reading data, inspecting structure, filtering, and indexing. Example:
import pandas as pd df = pd.read_csv("[Link]") print([Link]())
print(df[['Name','Department']].iloc[0:5])
Data Cleaning

Data often requires cleaning before analysis. Missing values, inconsistent types, and noisy strings
are common. Example:
df['Age'] = df['Age'].fillna(df['Age'].mean()) df['Department'] =
df['Department'].[Link]() df['JoinDate'] = pd.to_datetime(df['JoinDate'])
Data Transformation

Transformations help reshape or summarize data for insights. Example:


avg_salary = [Link]('Department')['Salary'].mean() pivot =
df.pivot_table(index='Department', values='Salary', aggfunc='mean') merged =
[Link](df1, df2, on='EmployeeID', how='inner')
Exploratory Data Analysis (EDA) with Python

EDA is the process of summarizing datasets to understand patterns, trends, and anomalies.
Example:
import seaborn as sns import [Link] as plt [Link](df['Salary'],
kde=True) [Link](x='Department', y='Salary', data=df) [Link]()
Case Study: Employee Dataset

Consider an employee dataset with Name, Age, Department, and Salary. Tasks include cleaning
missing values, grouping by department, and visualizing distributions. Steps: 1. Handle missing
Salary values 2. Group by Department to find averages 3. Visualize Salary distributions by
Department
Exercises

1. Count employees per department 2. Find top 5 salaries 3. Which department has the youngest
average age? 4. Plot salary distribution histogram
Interview Q&A; Bank (Python Focus)

Q: Difference between loc and iloc? A: loc uses label-based indexing; iloc uses integer-based
indexing. Q: When to use merge vs concat? A: merge joins on keys (like SQL joins), concat
appends along axis. Q: How do you handle missing values? A: Drop rows, fill with mean/median, or
impute. Q: How to optimize pandas operations on large datasets? A: Use vectorized ops, chunking,
or Dask for distributed processing.

You might also like