You are on page 1of 6

Data Handling with Pandas- I (Series)

1) Write a program to create a Series using a dictionary that stores the number of
students in each section of class 12 (A, B, C) in your school.
2) Write code to create a Series ‘S5’ using the Python sequence (11, 21, 31, 41).
3) Write code to create a Series ‘SO’ using the Python sequence [4, 6, 8, 10].
4) Write a program to create a Series using individual characters ‘o’, ‘h’ and ‘o’.
5) Write a program to create a Series object using a string “So funny” and predict the
output for the same.
6) Write a program to create a Series object using three different words ‘I’, ‘am’,
‘laughing’ and predict the output for the same.
7)

8)
9)

10) Given vls=pd.Series([11,23,61,87,93,112], index=[‘a’,’b’,’c’,’d’,’e’,’f’])


Consider a Series object vls, write statements to do the following:
(i) Retrieve the third element and print it.
(ii) Retrieve and print the first three elements.
(iii) Retrieve and print the last two elements.
(iv) Retrieve print alternate elements, starting from index ‘b’

11) Consider the following dictionary:


states={'A':'Andhra Pradesh', 'B':'Bihar', 'D':'Delhi', 'K':'Kerala', 'R':'Rajasthan', 'T':'Tamil
Nadu'}
Create a series from the above dictionary and write Python statements for the
following:
(i) To display 1st,3rd,5th elements of the series
(ii) To display all elements from 2nd to 5th present in the series.
(iii) To replace the value of index ‘K’ by ‘Karnataka’.
(iv) To display first three elements of the series
(v) To display last five elements of the series
12) Create series objects for the following:
(i) Storing value 100 with indexes as odd numbers from 1 to 10.
(ii) Storing numbers from 1 to 5 as indexes and their square values as data.
(iii) Storing value “Pass and Promoted” for 5 students with names: Ajay, Vikas, Sunesh,
Rita, Ramya Store names of the students as index of the series.
(iv) Series having 10 random numbers in the range of 10 and 20.
13) Write the output of the following code:
import pandas as pd 0 1 2 3 4
S1=pd.Series([31,28,31,30,31], index=[‘Jan’,’Feb’,’Mar’,’Apr’,’May’])
print(s1[0:2]*2)
14) Write the output of the following code:
import pandas as pd
s1=pd.Series((2,31)*2)
print(s1)

15) Write a program to modify the value 5000 to 7000 in the following series “S1”.
A 25000
B 12000
C 8000
D 5000

16) Write a code to create the given series from two different lists.

January 31
February 28
March 31
April 30
May 31
June 30

17) Which Property of series returns the number of elements in the series?

18) Write the output of the following code:

import pandas as pd
s1=pd.Series([2,5,7,10])

print(s1+2)

print(s1*2)

print(s1**2)

print(s1-2)

print(s1>2)

19) Write a program to display only those values greater than 200 in the Series S1.

0 300

1 100
2 1200
3 1700

20) Write a program to display the following Series S1 in descending order.

0 300

1 100
2 1200
3 1700

21) Write a program to display only those values greater than 200 in the given series
‘S1’.

0 300

1 100
2 1200
3 1700

22) Write the output of the following:

import pandas as pd

S1=pd.Series([3,1,12,17],index=(‘a’,’b’,’c’,’d’))
S2=pd.Series([4,5,6,7],index=(‘a’,’b’,’e’,’f’))

print(S1.mul(S2.fill_value=0))

23) Write a program to change the index of the following series “S1” from (0,1,2,3) to
(‘a’,’b’,’c’,’d’).

24) Consider the following series object “S1” and write the output of the following
statement.

import pandas as pd

L1=[21,41,62,81,23,45,68,89]

S1=pd.Series(L1)

print(“1.”,S1.index)

print(“2.”,S1.values)

print(“3.”,S1.shape)

print(“4.”,S1.ndim)

print(“5.”,S1.size)

print(“6.”,S1.nbytes)

print(“7.”,S

1[4])

print(“8.”,S1[2]+S1[0])

print(“9.”,S1[5]**2)

print(“10.”,S1.empty)

print(“11.\n”,S1[[1,5,6]])

print(“12.\n”,S1[5:7],”\n”)

print(“13.\n”,S1[ : :-1])
print(“14.\n”,S1>60)

print(“15.\n”,S1[S1>60])

print(“16.\n”,len(S1))

print(“17.\n”,S1.count())

25) Write the output of the following:


import pandas as pd
L1=[1,”A”,21]
S1=pd.Series(data=2*L1)
print(S1)

26) Name any 2 attributes of series in python.


27) Which property of series S1 will return all the index values?

28) Write the output of the given program:

import pandas as pd

S1=pd.Series([5,6,7,8,10],index=['v','w','x','y','z'])

l=[2,6,1,4,6]

S2=pd.Series(l,index=['z','y','a','w','v'])

print(S1-S2)

29) Create a series by concatenating your first name and last name.

30) What will be the output of the following code:

>>> import pandas as pd

>>> mydata=pd.Series( [‘rajesh’, ‘amit’, ‘tarun’, ‘Radhika’] )

>>> print(mydata < ‘rajesh’ )

*******************************************

You might also like