0% found this document useful (0 votes)
6 views2 pages

Xii Ip Module2

The document is a lesson plan for Class XII Informatics Practices, focusing on data handling using Python Pandas, specifically on creating Series in various ways. It covers topics such as creating empty Series, Series from lists and NumPy arrays, customizing indices, handling NaN values, and using dictionaries. Additionally, it includes coding assignments for students to practice their skills in creating Series.
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)
6 views2 pages

Xii Ip Module2

The document is a lesson plan for Class XII Informatics Practices, focusing on data handling using Python Pandas, specifically on creating Series in various ways. It covers topics such as creating empty Series, Series from lists and NumPy arrays, customizing indices, handling NaN values, and using dictionaries. Additionally, it includes coding assignments for students to practice their skills in creating Series.
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
You are on page 1/ 2

KENDRIYA VIDYALAYA NO1 SAMBALPUR

CLASS – XII SUBJECT : INFORMATICS PRACTICES

CHAPTER : DATA HANDLING USING PANDAS - I


Topics to be covered : Creating Series using different ways

Instructions to the students :


Dear students, in this topic, we are going to discuss about Series of Python Pandas and
different ways to create Series.
Read and write the following in your classwork notebook.

Introduction to Series:
Series is a one-dimensional array like structure with homogeneous data, which can be used to
handle and manipulate data. It has two parts : Data part (An array of actual data) and
Associated index with data (associated array of indexes or data labels).
Creating an Empty Series : A series without any element is known as Empty series. Series()
method without any argument is used to create empty series. Try the following codes -
import pandas as pd
d1 = pd.Series()
print(d1) # Output : [] dtype : float64 Output :
Creating Series using List : Series() is used to create a Series. 0 5
Try the following codes :- 1 15
import pandas as pd 2 25
arr=[5, 15, 25, 35, 50] # List arr is created 3 35
s1= pd.Series(arr) # Series s1 is created using List arr 4 50
print(s1) dtype: int64
Creating Series using NumPy Array :
Output :
Series can be created using NumPy array. Try the following codes :-
0 5
import pandas as pd 1 15
import numpy as np 2 25
arr=np.array([5, 15, 25, 35, 50]) 3 35
s1= pd.Series(arr) 4 50
print(s1) dtype: int32
Creating Series using List with customizing indices :
Index of Series is mutable. We can change default index values in pandas series. Default
index values in pandas series are 0, 1, 2, 3, 4 … .
Output :
We can create Series using List with customizing indices. First 5
import pandas as pd Second 15
arr=[5, 15, 25, 35] Third 25
s1= pd.Series(arr, index=['First','Second','Third','Fourth']) Fourth 35
print(s1) dtype: int64
Creating Series using NumPy Array with customizing indices :
Index of NumPy array is not mutable but Index of Series is mutable.
We can create Series using NumPy Array with customizing indices. Try the following codes–
import pandas as pd Output :
import numpy as np First 5
arr=np.array([5, 15, 25, 35]) Second 15
s1= pd.Series(arr, index=['First','Second','Third','Fourth']) Third 25
print(s1) Fourth 35
dtype: int32
Creating Series using Mathematical Function : Output :
We use mathematical functions in Series() to create a Series. 1 1.0
import pandas as pd 4 2.0
import numpy as np 9 3.0
arr=np.array([1, 4, 9, 16, 25]) 16 4.0
s1= pd.Series(np.sqrt(arr), index=arr) 25 5.0
print(s1) dtype: float64
Creating Series with NaN values :
In Python, specifically in Pandas, NumPy we mark missing values as NaN. Values with a
NaN value are ignored from operations like sum, counts etc. Series can be created with NaN
values also. Try the following codes– Output :
import pandas as pd 1st 5.0
import numpy as np 2nd NaN
arr=np.array([5, np.NaN, 25, np.NaN, 50]) 3rd 25.0
s1= pd.Series(arr, index=['1st','2nd','3rd','4th','5th']) 4th NaN
print(s1) 5th 50.0
dtype: float64
Creating Series with NaN values :
To create a series from scalar value (constant value), an index must be provided. The scalar
value will be repeated as per the length of index.
Output :
Try the following codes– 1st 25
2nd 25
import pandas as pd 3rd 25
s1= pd.Series(25, index=['1st','2nd','3rd','4th']) 4th 25
print(s1) dtype: int64

Try the following codes– Output :


import pandas as pd 1st Rama
s1= pd.Series(‘Rama’, index=['1st','2nd','3rd','4th']) 2nd Rama
print(s1) 3rd Rama
4th Rama
dtype: object
Creating Series using Dictionary : Series can be created using dictionary.
Try the following codes– Output :
import pandas as pd RollNo 1201
d1={'RollNo':1201,'Name':'Ramesh','Mark':99} Name Ramesh
s1= pd.Series(d1) Mark 99
dtype: object
print(s1)

Assignment: Write the Python Coding for the following in your classwork notebook.
Q1. Q2. Q3.
Write python code to create the Write python code to Write python code
below series using NumPy array : create the below to create the below
Mon 15 series using series using List :
Tue 23 dictionary : I 65
Wed 32 Jan 31 II 78
Thu 41 Feb 28 III 82
Fri 52 Mar 31 IV 98
Sat 66 V 48
Sun 70

Prepared by : Sanatan Banji, PGT Comp.Sc., KV No1 Sambalpur, Mob. No. : 9583825083

You might also like