Entrance Announcement
MICTE 2080
2080 Magh 07
User:Niraj/Teaching-19
Jump to navigation
Jump to search
Teaching lesson plan 19 Subject: Python programming
Date: 5 Feb 2024
Time: 60 minutes
Period: 3rd
Teaching Item: Introduction to Series in Pandas
Class: Bachelor
Objective:
Students will learn about Series in pandas, understand their structure and capabilities, and apply them to manipulate and analyze one-dimensional labeled data effectively.
Materials Needed:
- Python interpreter with pandas installed
- Jupyter Notebook or any Python IDE
- Sample dataset (e.g., CSV file)
- Projector
1. Introduction to Pandas and Series (10 mins)
- Brief overview of pandas library:
- Pandas is a powerful data manipulation and analysis library in Python.
- It provides data structures and functions for working with structured data, similar to R's data frames.
- Introduce the concept of Series in pandas:
- Series is a one-dimensional labeled array capable of holding any data type (e.g., integers, strings, floats, etc.).
- Each element in a Series has a corresponding label, called an index.
2. Creating Series (15 mins)
- Discuss different ways to create Series objects in pandas:
- From a Python list or NumPy array.
- Using a dictionary where keys become the index labels.
- Specifying data and index separately.
- Using built-in functions like
pd.Series()
.
- Demonstrate each method with examples and discuss their advantages.
3. Accessing Elements and Indexing (15 mins)
- Explain how to access elements and perform indexing on Series:
- Using integer-based indexing.
- Using label-based indexing.
- Slicing for selecting subsets of data.
- Show examples of accessing elements and performing indexing operations on Series.
4. Operations on Series (15 mins)
- Discuss various operations that can be performed on Series:
- Arithmetic operations (e.g., addition, subtraction, multiplication, division).
- Element-wise mathematical functions (e.g.,
np.sqrt()
,np.log()
). - Comparison operations (e.g., greater than, less than).
- Boolean indexing for filtering data.
- Demonstrate each operation with examples and discuss their applications.
5. Handling Missing Data (10 mins)
- Introduce techniques for handling missing data (NaN) in Series:
pd.isnull()
andpd.notnull()
functions for detecting missing values.fillna()
method for filling missing values with specified values.dropna()
method for removing rows with missing values.
- Show examples of handling missing data in Series.
6. Exercise (15 mins)
- Provide a programming exercise where students:
- Load a sample dataset into a pandas Series.
- Perform indexing, slicing, and filtering operations on the Series.
- Apply arithmetic operations and mathematical functions to manipulate the data.
- Handle missing data using appropriate techniques.
7. Conclusion (5 mins)
- Recap the key points covered in the lesson:
- Series in pandas are one-dimensional labeled arrays capable of holding any data type.
- Series can be created from Python lists, dictionaries, NumPy arrays, or by specifying data and index separately.
- Operations such as indexing, slicing, arithmetic operations, and handling missing data can be performed on Series.
- Encourage students to practice using Series in pandas for data manipulation tasks and to explore additional functionalities offered by the library.