Thursday, 11 March 2021

Class 12 IP Practical - 12

 12.  Create a Series and access the top 2 and last 2 elements using head() and tail() methods.


import pandas as pd

d=[10,20,30,40,50,60,70,80]

S=pd.Series(d)

print("Series:")

print(S)

print("Top 2 Elements of Series:")

print(S.head(2))

print("Last 2 Elements of Series:")

print(S.tail(2))



 

========= RESTART: C:/Program Files (x86)/Python38-32/IP-12.py ========

Series:

0    10

1    20

2    30

3    40

4    50

5    60

6    70

7    80

dtype: int64

Top 2 Elements of Series:

0    10

1    20

dtype: int64

Last 2 Elements of Series:

6    70

7    80

dtype: int64

>>>  

No comments:

Post a comment