Page 17 - Informatics_Practices_Fliipbook_Class12
P. 17
For example, if integer values are mixed with floating point values, all of them will be converted to floating point
values, as shown below:
>>> import pandas as pd
>>> marks = [90.5, 70, 95, 45, 100] #Creating Pandas Series using list
>>> marksSeries = pd.Series(marks)
>>> print(marksSeries) #all values typecasted to float type
0 90.5
1 70.0
2 95.0
3 45.0
4 100.0
dtype: float64
Let's consider a scenario where the fifth student was absent for the exam. In such a case, the absence can be represented
in the list using the value None. However, when we create a series object, Pandas replaces None by NaN (short for not
a number).
>>> marks = [90.5, 70, 95, 45, None] #Creating Pandas Series using list
>>> marksSeries = pd.Series(marks)
>>> print(marksSeries) #all values typecasted to float type
0 90.5
1 70.0
2 95.0
3 45.0
4 NaN
dtype: float64
As illustrated below explicitly, NaN represents a null object of type float64:
>>> type(marksSeries[4])
output:
numpy.float64
In Python, all types (classes) are considered as subclasses of the common class object. So, objects of seemingly
unrelated types are cast to this common type object. For example, let us consider a series object representing roll
number, name, and marks in three subjects:
>>> import pandas as pd
>>> student = [23, 'Radhe Shyam', [90, 80, 91]]
>>> studentSeries = pd.Series(student)
>>> print(studentSeries)
output:
0 23
1 Radhe Shyam
2 [90, 80, 91]
dtype: object
Note that all values are typecast to object type.
1.2 Indexing and Slicing
Now, that you are comfortable with Pandas series, we will drop the suffix series from the names of series. So, we create
a series, called students, denoting the marks of students.
>>> import pandas as pd
>>> marks = [90, 75, 95, 45, 100] #Creating Pandas Series using list
>>> students = pd.Series(marks)
>>> print(students)
output:
0 90
1 75
2 95
3 45
Data Handling using Pandas 3

