0% found this document useful (0 votes)
83 views5 pages

Series Worksheet Answer

This document is a worksheet for Class XII CBSE Informatics Practices at New Indian Model School, Sharjah. It includes questions and answers related to the Pandas library in Python, covering topics such as series creation, functions, and data manipulation. The document also contains programming tasks and expected outputs for students to practice their coding skills with Pandas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views5 pages

Series Worksheet Answer

This document is a worksheet for Class XII CBSE Informatics Practices at New Indian Model School, Sharjah. It includes questions and answers related to the Pandas library in Python, covering topics such as series creation, functions, and data manipulation. The document also contains programming tasks and expected outputs for students to practice their coding skills with Pandas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

NEW INDIAN MODEL SCHOOL, SHARJAH

INFORMATICS PRACTICES
SERIES WORKSHEET Class: XII CBSE

1. _______ is a one-dimensional labelled data structure capable of holding any data type.
Ans: Series
2. If data is a ndarray, ______________ must be same length as data.
Ans: index
3. Pandas was developed by ______________ in 2008.
Ans: Wes Mckinney
4. head() function is used to get the ______________ n rows.
Ans: first
5. If data is ____________, an index must be provided.
Ans: scalar value
6. ____________ function is used to add two series.
Ans: add()
7. What is the syntax for creating a series
(A) <series name>=pandas.Series(<list name>,...)
(B) <series name>=pandas.Series(<dictionary name>,...)
(C) <series name>=pandas.Series(<array name>,...)
(D) <series name>=pandas.Series(<scalar value>,…)
(E) All the above
8. Which of the following is used to create an empty series object
(A) pd.Series(empty) (B) pd.Series(np.NaN)
(C) pd.Series( ) (D) All of these
9. Which of the following is used to get the number of dimensions of a Series object
(A) index (B) size (C) itemsize (D) ndim
10.Which of the following is used to get the number of elements in a Series object
(A) index (B) size (C) itemsize (D) ndim
11.What is the use of head( ) function with a Series
(A) Display the last five elements of a Series
(B) Displays the first five elements of a Series
(C) Removes the first five elements of a Series
(D) Removes the last five elements of a Series
12.Identify the correct statement:
(A) The standard marker for missing data in Pandas is NaN
(B) Series act in a way similar to that of an array
(C) Both of the above
(D) None of the above
13.Minimum number of argument we require to pass in pandas series ?
(A) 0 (B) 1 (C) 2 (D) 3
14.Series in Pandas is
(A) 1 dimensional array (B) 2-dimensional array
(C) 3-dimensional array (D) None of the above
15.Which of the following thing can be data in Pandas?
(A) a python dict (B) an ndarray
(C) a scalar value (D) all of the mentioned
16.Point out the correct statement.
(A) If data is a list, if index is passed the values in data corresponding to the labels in the
index will be pulled out
(B) NaN is the standard missing data marker used in pandas
(C) Series acts very similarly to an array
(D) None of the mentioned
17.Which command is used for installing the Pandas?
(A) pip install python–pandas (B) pip install pandas
(C) python install python (D) python install pandas

18. In pandas, S in a series with following data :


S=pd.Series([5,10,15,20,25])
Find the output of S[1:3]
Ans:
1 10
2 15
dtype: int64

19.Create a pandas series D from the dictionary


day = {‘Sun’:4500, ‘Mon’:3200, ‘Tue’:4700, ‘Wed’:4600, ‘Thu’:4000,
‘Fri’:3800,‘Sat’:4200}
Display the series D and display the last 4 rows.
Ans:
import pandas as pd
day=({'Sun':4500,'Mon':3200,'Tue'4700,'Wed':4600,'Thu':4000,'Fri':3800,'Sat': 4200})
D=pd.series(day)
print(D)
print(D.tail(4))

20.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 series.
Ans:
import numpy as np
import pandas as pd
p=np.arange(10,101,5)
G=pd.Series(p)
print(G)
21.Write a Python program to count non-nan values in the series.
Ans:
import pandas as pd
import numpy as np
s2=pd.Series([pd.NaT,np.nan,10])
print(s2)
print("count of non null values",s2.count())
Output
0 NaT
1 NaN
2 10
dtype: object
count of non null values 1

22.Write Python code to create the following series S.


101
201
301
401
501
Display the first two rows.
Ans:
import pandas as pd
S=pd.Series(range(101,502,100))
print(S)
print('First two rows::')
print(S.head(2))

23.Write python statement to reverse a series named s.


Ans: print(s[::-1])

24.Write the python statement to find the dimension, size and values of a series named s.
Ans:
print(s.ndim)
print(s.size)
print(s.values)

25.Write a python statement to display 3rd and 2nd value of the Series s in that order.
Ans: print(s[2:0:-1])
26.Write python code to create the series Student which has the roll numbers and marks secured
by 5 students. Display the roll number and marks of the students whose marks are above 80.
Ans:
import pandas as pd
mark=[96.5,58.0,77.5,81.0,67.5]
rollno=[1,2,3,4,5]
student=pd.Series(data=mark, index=rollno)
print("Students who secured above 80")
print(student[student>80])
Output
Students who secured above 80
1 96.5
4 81.0
dtype: float64

27. Create a Series having 5 elements with index labels ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ and all the five
values set to zero.
Ans:
import pandas as pd
s=pd.Series(0,index=['a','e','i','o','u'])
print(s)

28.Create a series Month (from Jan-May) , from a dictionary having number of days as data and
month name as keys.
Ans:
import pandas as pd
d1={'jan':31,'feb':28,'mar':31,'apr':30,'may':31}
s=pd.Series(d1)
print(s)

29.The following Series shows the marks of 5 students.

Write Python command for the following.


a) Replace the index with student name as [Anoop, Rayan, Meena, Diya, Mahesh].
b) Rename the Series as “Mark List”
c) Display the first 2 students’ marks from the series.
d) Display Meena’s mark from the series
e) Display Anoop’s and Diya’s mark from the series.
f) Change Rayan’s mark as 96
g) Display the dimension and size of the series
h) Display the students having mark more than 90
i) Display the failed students (passing mark is 33)

Ans:
a) s.index=['Anoop','Rayan','Meena','Diya','Mahesh']
b) s.name='MarkList'
c) print(s.head(2))
d) print(s['Meena'])
e) print(s[['Anoop',’ Diya’]])
f) s[‘Rayan’]=96
g) print(s.ndim), print(s.size)
h) print(s[s>90])
i) print(s[s<33])

30.Consider the following series Item1 and Item2

Item1 Item2

Write output for the following


a) Item1+Item2 b) Item1-Item2

Ans:

a) b)

You might also like