Page 455 - AI Ver 3.0 class 10_Flipbook
P. 455
Attributes of the Series
Following table shows some attributes of the Series:
Attribute Description Example
name A name to a series is
[1]: import pandas as pd
given import numpy as np
data = np.array([10,30,50])
s1 = pd.Series(data)
s1.name="Rollno"
print(s1)
0 10
1 30
2 50
Name: Rollno, dtype: int32
index. A name to an index is
[1]: s1.index.name="Students"
name given print(s1)
Students
0 10
1 30
2 50
Name: Rollno, dtype: int32
value Returns the list of values
[1]: print(s1.values)
in the series
[10 30 50]
size Returns the number of
[1]: print(s1.size)
values in the series
3
empty Returns True if the series
[1]: print(s1.empty)
is empty.
False
Built in Functions in Series
Following table shows some built in functions of the Series:
Function Description Example
head(n) Returns the first n
[1]: import pandas as pd
members of the series. friends = pd.Series(["Rohan","Susan",
If n not specified then "James","Riya","Sumit","Abhinav","vihaan"],
index=[11,22,33,44,55,66,77])
by default first five
print(friends.head(2))
members are displayed.
11 Rohan
22 Susan
dtype: object
Advance Python (Practical) 453

