WS1 DataHandlingUsingPandas1
WS1 DataHandlingUsingPandas1
Instructions:
Write all the answers in the notebook. Submit to your respective teacher within a
week
4) Write a Python Program to create a Series G from a numpy array with values in the
range 10 to 100 (both values inclusive) in steps of 5 and print all the elements.
5) Write a program to create a series from dictionary that stores classes (6,7,8,9,10) as
keys and number of students as values.
6) Pushpa, a student of class-XII, has been assigned a code to create a pandas series
S1, as shown below.
a 100
b 200
c 300
d 400
e 500
dtype: int64
With reference to the above, answer the given questions:
i. Choose the command that will give the following output:
b 200
c 300
dtype: int64
a. print(S1[:3]) b. print(S1[0:3]) c. print(S1[2:4]) d. print(S1[1:3])
ii. Help him to identify the correct statement that can be used to extract the value
with the index 'c':
a. print(S1[c]) b. print(S1(c)) c. print('S1' ['c']) d. print(S1 ['c'])
7) Write python code to create the following series Student which has the roll
numbers and marks secured by 5 students.
1 96.5
2 58.0
3 77.5
4 81.0
5 67.5
Display the roll number and marks of the students whose marks are above 80.
8) Write a Python Program to create two Series objects J and K and find the
difference between K and J.
J K
A 20 B 12
B 10 C 5
C 30 D 8
9) Write the output of the following:
a) import pandas as pd
S1 =pd.Series(range(1,15,3), index=[x for x in "super"])
print(S1)
b) import numpy as num
import pandas as pd
arr=num.array([31,47,121])
S1 = pd.Series(arr, index = (7,77,777))
print(S1[777])
c) import pandas as pd
L1 = list("My name is Ravi Kumar")
S1 = pd.Series(L1)
print(S1[0])
14) Write the output of the following statements (i), (ii), (iii),(iv) & (v)
import pandas as pd
S1 = pd.Series([2, 5, 7, 10])
print(S1 + 2) -----------------------(i)
print(S1 * 2) -----------------------(ii)
print(S1 ** 2)-----------------------(iii)
print(S1 - 2) ------------------------(iv)
print(S1 > 2) ------------------------(v)
15) Answer the following based on the series given below: Write the output for the
statements 1,2,3 ,4 and 5
import pandas as pd
list1=[1,2,3,4,5,6,7,8]
list2=['swimming','tt','skating','kho kho', 'bb', 'chess', 'football',"cricket"]
school=pd.Series(list1,index=list2)
school.name=("little")
print (school*2) #statement 1
print (school.tail(3)) # statement 2
print (school["tt"]) # statement 3
print (school[2:4]) # statement 4
print(school[[1,2]] #statement 5
ii. Write the statement in python to list the games with less than 5 points
16) Answer the question based on the Assertion A and Reason R given.
A:A Series is a one-dimensional array containing a sequence of values of any data
type (int, float, list, string, etc).
R:Pandas Series can be imagined as a column in a spreadsheet.
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
e. Both A and R are false.
17) Assertion (A) : pandas is an open source Python library which offers high performance,
easy-to-use data
structures and data analysis tools.
Reason (R) : Professionals and developers are using the pandas library in data science
and machine learning.
A. Both A and R are true and R is the correct explanation of A
B. Both A and R are true but R is not the correct explanation of A
C. A is true but R is false
D. A is false but R is true
E. Both A and R are false
18) Choose the correct code that produces the output below:
9 18
10 20
11 22
12 24
a. a=np.arange(9, 13)
s1=pd.Series(index=a, data=a*2)
print(s1)
b. a=[9, 10, 11, 12]
s1=pd.Series(index=a, data=a*2)
print(s1)
c. Both the above
d. None of the above