Pandas Series Class 12 IP Important Questions

Q1. What do you mean by Pandas in Python?
Q2. Name three data structures available in Pandas.
Q3. Write command to install pandas in python.
Q4. What do you mean by Series in Python?
Index Value
0 Arnab
1 Samridhi
2 Ramit
3 Divyam
4 Kritika
Q5. Define data structure in Python.
Q6. Write the code in python to create an empty Series.
Ans. import pandas as pd S1 = pd.Series( ) print(S1) OR import pandas as pd S1 = pd.Series( None) print(S1) OUTPUT : Series([ ], dtype: float64)
Q7. Name a method which is used to create Series in Python.
Q8. Write a program in Python to create a series of first five even numbers.
Ans. import pandas as pd S1 = pd.Series([2, 4, 6, 8, 10]) print(S1) OUTPUT : 0 2 1 4 2 6 3 8 4 10 dtype: int64
Q9. Write a program in Python to create series of vowels.
Ans. import pandas as pd S1 = pd.Series(["a","e","i","o","u"]) print(S1) OUTPUT : 0 a 1 e 2 i 3 o 4 u dtype: object
Q10. Write a program in python to create series of given tuple : A = (11, 22, 33, 44, 55)
Ans. import pandas as pd A = (11, 22, 33, 44, 55) S1 = pd.Series(A) print(S1) OUTPUT : 0 11 1 22 2 33 3 44 4 55 dtype: int64
Q11. Write a program in Python to create the pandas series of all the characters in the name accepted from user.
Ans. import pandas as pd A = input("Enter your name : ") S1 = pd.Series(list(A)) print(S1) OUTPUT : Enter your name : amit 0 a 1 m 2 i 3 t dtype: object
Q12. Write a program in Python to create a Series in Python from the given dictionary. D = {“Jan” : 31, “Feb” : 28, “Mar” : 31}
Ans. import pandas as pd D = {"Jan" : 31, "Feb" : 28, "Mar" : 31} S1 = pd.Series(D) print(S1) OUTPUT : Jan 31 Feb 28 Mar 31 dtype: int64
Q13. 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.
Ans. import pandas as pd D = {6 : 140, 7 : 125, 8 : 100, 9 : 136, 10 : 200} S1 = pd.Series(D) print(S1) OUTPUT : 6 140 7 125 8 100 9 136 10 200 dtype: int64
Q14. Write the output of the following :
import pandas as pd S1 = pd.Series(12, index = [4, 6, 8]) print(S1)
Ans. Output is : 4 12 6 12 8 12 dtype: int64
Q15. Write the output of the following :
import pandas as pd S1 = pd.Series(range(1,15,3), index=[x for x in "super"]) print(S1)
Ans. s 1 u 4 p 7 e 10 r 13 dtype: int64
Pandas Series Class 12 IP Important Questions
Q16. Write the output of the following :
import pandas as pd S1 = pd.Series(range(100, 150, 10), index=[x for x in "My name is Amit Gandhi".split()]) print(S1)
Ans. My 100 name 110 is 120 Amit 130 Gandhi 140 dtype: int64
Q17. Write the output of the following :
import pandas as pd L1=[1,"A",21] S1 = pd.Series(data=2*L1) print(S1)
Ans. 0 1 1 A 2 21 3 1 4 A 5 21 dtype: object
Q18. Name any two attributes of Series in Python.
Q19. Which property of series return all the index value?
Q20. Write the output of the following :
import numpy as num import pandas as pd arr=num.array([1,7,21]) S1 = pd.Series(arr) print(S1)
Ans. 0 1 1 7 2 21 dtype: int32
Pandas Series Class 12 IP Important Questions
Q21. Write the output of the following :
import numpy as num import pandas as pd arr=num.array([1,7,21]) S1 = pd.Series(arr, index = (77,777)) print(S1)
Q22. Write the output of the following :
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])
Q23. Write the output of the following :
import numpy as num import pandas as pd arr=num.array([31,47,121]) S1 = pd.Series(arr) print(S1[0])
Q24. Write the output of the following :
import pandas as pd
L1 = list("My name is Ravi Kumar")
S1 = pd.Series(L1)
print(S1[0])Q25. Write the output of the following :
import pandas as pd
L1 = list("My name is Ravi Kumar".split( ))
S1 = pd.Series(L1)
print(S1[0])Pandas Series Class 12 IP Important Questions
Q26. Which property of series returns the number of elements in the series?
Q27. Give an example of creating series from NumPy array.
Ans. import pandas as pd import numpy as np arr = np.array([1,2,3,4,5]) S1 = pd.Series(arr) print(S1)
Q28. Which property of Series help to check whether a Series is empty or not? Explain with example
Ans. empty property : This property returns True if the Series is empty otherwise return False. import pandas as pd S1 = pd.Series() print(S1.empty) OUTPUT : True
Q29. Fill in the blanks in the given code :
import pandas as pd ____________ = ____________.Series([1, 2, 3, 4, 5]) print(S1)
Ans. import pandas as pd S1 = pd.Series([1, 2, 3, 4, 5]) print(S1)
Q30. Fill in the blank of given code, if the output is 71.
import pandas as pd S1 = pd.Series([10, 20, 30, 40, 71,50]) print(S1[ __________ ])
Ans. import pandas as pd S1 = pd.Series([10, 20, 30, 40, 71,50]) print(S1[ 4 ])
Pandas Series Class 12 IP Important Questions
Q31. Complete the code to get the required output :
import ______ as pd ________ = pd.Series([31, 28, 31], index = ["Jan", "Feb", "Mar"] ) print(S1["_______"]) OUTPUT : 28
Ans. import pandas as pd S1 = pd.Series([31,28,31], index = ["Jan","Feb","Mar"]) print(S1["Feb"])
Q32. Write the output of the following code :
import pandas as pd
S1 = pd.Series([31, 28, 31, 30, 31], index = ["Jan", "Feb", "Mar", "Apr", "May"])
print("-----------")
print(S1[1:3])
print("-----------")
print(S1[:5])
print("-----------")
print(S1[3:3])
print("-----------")
print(S1["Jan":"May"])Ans. ----------- Feb 28 Mar 31 dtype: int64 ----------- Jan 31 Feb 28 Mar 31 Apr 30 May 31 dtype: int64 ----------- Series([ ], dtype: int64) ----------- Jan 31 Feb 28 Mar 31 Apr 30 May 31 dtype: int64
Q33. Write the output of the following code :
import pandas as pd S1 = pd.Series([31, 28, 31, 30, 31], index = ["Jan", "Feb", "Mar", "Apr", "May"]) print(S1["Jun"])
Q34. Write the output of the following code :
import pandas as pd S1 = pd.Series([31, 28, 31, 30, 31], index = ["Jan", "Feb", "May", "Apr", "May"]) print(S1["May"])
Ans. May 31 May 31 dtype: int64
Q35. Write the output of the following :
import pandas as pd S1 = pd.Series([31, 28, 31, 30, 31], index = ["Jan", "Feb", "Mar", "Apr", "May"]) print(S1[ [0, 2, 4] ])
Ans. Jan 31 Mar 31 May 31 dtype: int64
Q36. Write the output of the following :
import pandas as pd S1 = pd.Series([31, 28, 31, 30, 31], index = ["Jan", "Feb", "Mar", "Apr", "May"]) print(S1[0 : 2] * 2)
Ans. Jan 62 Feb 56 dtype: int64
Q37. Write a program to modify the value 5000 to 7000 in the following Series “S1”
A 25000 B 12000 C 8000 D 5000
Ans. import pandas as pd S1[3]=7000 print(S1)
Q38. Explain any two properties/attributes of Pandas Series.
Q39. Explain any three methods of Pandas Series.
1) head(n) : This function returns the first n members of the series. If the value for n is not passed, then by default n takes 5 and the first five members are displayed. 2) tail( n) : This function returns the last n members of the series. If the value for n is not passed, then by default n takes 5 and the last five members are displayed. 3) count( ) : This function returns the number of non-NaN values in the Series.
Q40. 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)
Ans. 0 4 1 7 2 9 3 12 dtype: int64 0 4 1 10 2 14 3 20 dtype: int64 0 4 1 25 2 49 3 100 dtype: int64 0 0 1 3 2 5 3 8 dtype: int64 0 False 1 True 2 True 3 True dtype: bool
Q41. Write the output of the following code :
import pandas as pd S1 = pd.Series([2, 5, 7, 10]) S2 = pd.Series([1, 3, 5, 7]) print(S1 + S2)
Ans. 0 3 1 8 2 12 3 17 dtype: int64
Q42. Write a program to display only those values greater than 200 in the given Series “S1”
0 300 1 100 2 1200 3 1700
Ans. import pandas as pd S1 = pd.Series([300, 100, 1200, 1700]) print(S1[S1>200])
Q43. Write a program to display the following Series “S1” in descending order.
0 300
1 100
2 1200
3 1700
Ans. import pandas as pd S1 = pd.Series([300, 100, 1200, 1700]) print(S1.sort_values(ascending=False)) #if given True then Series will arrange in ascending order OUTPUT : 3 1700 2 1200 0 300 1 100 dtype: int64
Q44. 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*S2)Ans. a 12.0 b 5.0 c NaN d NaN e NaN f NaN dtype: float64
Q45. 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))Ans. a 12.0 b 5.0 c 0.0 d 0.0 e 0.0 f 0.0 dtype: float64
Q46. Name the methods used for multiplication and division of two Series in Python.
Method used for multiplication of two Series is div( )
Q47. Differentiate between Pandas Series and NumPy Arrays.
Pandas Series NumPy Arrays In series we can define our own labeled index to
access elements of an array.In NumPy Arrays we can not define our own labeled
index to access elements of an arraySeries require more memory NumPy occupies lesser memory. The elements can be indexed in descending order also. The indexing starts with zero for the first
element and the index is fixed
Q48. A Series object can have duplicate index.(T/F)
Q49. A Series object always have indexes 0 to n-1. (T/F)
Q50. ________________ is a Pandas data structure that represent one dimensional array containing a sequence of values of any data type
Q51. Write a program to change the index of the following Series “S1” from (0, 1, 2, 3) to (a, b, c,d).
0 120 1 75 2 85 3 95
Ans. import pandas as pd S1 = pd.Series([120, 75, 85 ,95]) print("Initial Index Values are : ") print(S1) print("Final Index Values are : ") S1.index=("a","b","c","d") print(S1) OUTPUT : Initial Index Values are : 0 120 1 75 2 85 3 95 dtype: int64 Final Index Values are : a 120 b 75 c 85 d 95 dtype: int64
Q52. Write the output of the following :
import pandas as pd L1=[1, 2, 3, 4] S1 = pd.Series(L1 * 2) S2 = pd.Series(S1 * 2) print(S1) print(S2)
Ans. 0 1 1 2 2 3 3 4 4 1 5 2 6 3 7 4 dtype: int64 0 2 1 4 2 6 3 8 4 2 5 4 6 6 7 8 dtype: int64
Q53. Consider the following Series object “S1” and write the output of the following statement :
0 21
1 41
2 62
3 81
4 23
5 45
6 68
7 89
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. ",S1[0])
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())
print("18.\n",S1.head())
print("19.\n",S1.tail())
print("20.\n",S1[4:5] + S1[4:5])Ans. 1. RangeIndex(start=0, stop=8, step=1) 2. [21 41 62 81 23 45 68 89] 3. (8,) 4. 1 5. 8 6. 64 7. 21 8. 83 9. 2025 10. False 11. 1 41 5 45 6 68 dtype: int64 12. 5 45 6 68 dtype: int64 13. 7 89 6 68 5 45 4 23 3 81 2 62 1 41 0 21 dtype: int64 14. 0 False 1 False 2 True 3 True 4 False 5 False 6 True 7 True dtype: bool 15. 2 62 3 81 6 68 7 89 dtype: int64 16. 8 17. 8 18. 0 21 1 41 2 62 3 81 4 23 dtype: int64 19. 3 81 4 23 5 45 6 68 7 89 dtype: int64 20. 4 46 dtype: int64
Q54. Consider the following Series object “S1” and “S2” and write the output of the following code :
| S1 | S2 |
| 0 2 1 4 2 6 3 8 4 10 | 0 1 1 2 2 3 3 4 4 5 |
import pandas as pd S1=pd.Series([2, 4, 6, 8, 10]) S2=pd.Series([1, 2, 3, 4, 5]) print(S1+S2) print(S1-S2) print(S1*S2) print(S1/S2) print(S1.mul(2)) print(S1*3) print(S1+3) print(S1-3) print(S1.div(S2))
Ans. 0 3 1 6 2 9 3 12 4 15 dtype: int64 0 1 1 2 2 3 3 4 4 5 dtype: int64 0 2 1 8 2 18 3 32 4 50 dtype: int64 0 2.0 1 2.0 2 2.0 3 2.0 4 2.0 dtype: float64 0 4 1 8 2 12 3 16 4 20 dtype: int64 0 6 1 12 2 18 3 24 4 30 dtype: int64 0 5 1 7 2 9 3 11 4 13 dtype: int64 0 -1 1 1 2 3 3 5 4 7 dtype: int64 0 2.0 1 2.0 2 2.0 3 2.0 4 2.0 dtype: float64
Q55. Write a program to perform basic mathematical operation on two series.
Ans. import pandas as pd S1=pd.Series([2, 4, 6, 8, 10]) S2=pd.Series([1, 2, 3, 4, 5]) print(S1+S2) #Addition print(S1-S2) #Subtraction print(S1*S2) #Multiplication print(S1/S2) #Division
Q56. Write a program to create series from the given dictionary. D={ “A” : “Apple”, “B” : “Boy”, “C” : “Cat”}
Ans. import pandas as pd D={ "A" : "Apple", "B" : "Boy", "C" : "Cat"} S1 = pd.Series(D) print(S1) OUTPUT : A Apple B Boy C Cat dtype: object
Q57. Write a program to create Pandas Series from the given NumPy array. A=[1,2,3,4,5,6,7]
Ans. import pandas as pd import numpy as np A = np.array([1,2,3,4,5,6,7]) S1 = pd.Series(A) print(S1) OUTPUT : 0 1 1 2 2 3 3 4 4 5 5 6 6 7 dtype: int32
Q58. Write a program to display only first n rows from the given Pandas Series ‘S1’. Accept n from the user.
0 1
1 2
2 3
3 4
4 5
5 6
6 7
Ans. import pandas as pd nt = int(input("Enter number of terms to display")) S1 = pd.Series([1, 2, 3, 4, 5, 6, 7]) print(S1.head(nt)) OUTPUT : Enter number of terms to display : 4 0 1 1 2 2 3 3 4 dtype: int64
Q59. Write a program to display values greater than 250 from the given Pandas Series “S1”
0 150 1 252 2 35 3 420 4 50 5 61 6 275
Ans. import pandas as pd S1 = pd.Series([150, 252, 35, 420, 61, 275]) print(S1[S1>250]) OUTPUT : 1 252 3 420 5 275 dtype: int64
Q60. Write a program to count the number of values less than 200 from the given Pandas Series.
0 150
1 252
2 35
3 420
4 50
5 61
6 275
Ans. import pandas as pd S1 = pd.Series([150, 252, 35, 420, 61, 275]) print(S1[S1<200].count( )) OUTPUT : 3
Q61. Write a program to increase those value in the given Pandas Series by 50 which are less than 70.
0 150
1 252
2 35
3 420
4 50
5 61
6 275
Ans. import pandas as pd S1 = pd.Series([150, 252, 35, 420, 61, 275]) S1[S1<70] = S1[S1<70] + 50 print(S1) OUTPUT : 0 150 1 252 2 85 3 420 4 111 5 275 dtype: int64
Q62. Write a program to create a Series whose values are characters of the name accepted from the user. for example :
Enter Your Name : Suman Series is : 0 S 1 u 2 m 3 a 4 n
Ans. import pandas as pd nm = input("Enter your name : ") S1 = pd.Series(list(nm)) print(S1) OUTPUT : Enter your name : amit 0 a 1 m 2 i 3 t dtype: object
Q63. Write a program to arrange the given Pandas Series in increasing order.
0 150
1 252
2 85
3 420
4 111
5 275
Ans. import pandas as pd S1 = pd.Series([150,252,85,420,111,235]) print("Original Series is : ") print(S1) print("New Series is : ") print(S1.sort_values()) OUTPUT : Original Series is : 0 150 1 252 2 85 3 420 4 111 5 235 dtype: int64 New Series is : 2 85 4 111 0 150 5 235 1 252 3 420 dtype: int64
Q64. Write a program to add a new value (Accept that value from the user) in the given Pandas Series.
0 150
1 252
2 85
3 420
4 111
5 275
Ans. import pandas as pd S1 = pd.Series([150, 252, 85, 420, 111, 235]) v = int(input("Enter any value : ")) print("Original Series is : ") print(S1) S1[6]=v print("New Series is : ") print(S1) OUTPUT : Enter any value : 677 Original Series is : 0 150 1 252 2 85 3 420 4 111 5 235 dtype: int64 New Series is : 0 150 1 252 2 85 3 420 4 111 5 235 6 677 dtype: int64
Q65. Write a program to display the sum and average of all the values in the given Pandas Series.
0 15 1 2 2 8 3 4 4 1 5 5 6 14
Ans. import pandas as pd S1 = pd.Series([15, 2, 8, 4, 1, 5, 14]) print("Sum is : ", sum(S1.values)) print("Average is : ", sum(S1.values)/S1.count( )) OUTPUT : Sum is : 49 Average is : 7.0
Q66. Write a program to find the minimum, maximum value of given Pandas Series.
0 15
1 2
2 8
3 4
4 1
5 5
6 14
Ans. import pandas as pd S1 = pd.Series([15,2,8,4,1,5,14]) print("Maximum value is : ",max(S1.values)) print("Minimum value is : ",min(S1.values)) OUTPUT : Maximum value is : 15 Minimum value is : 1
Q67. Write a program to display multiple of 5 from the given Pandas Series.
0 15 1 2 2 8 3 4 4 1 5 25 6 30
Ans. import pandas as pd S1 = pd.Series([15, 2, 8, 4, 1, 25, 30]) print(S1[S1.values%5==0]) OUTPUT : 0 15 5 25 6 30 dtype: int64
Q68. Write a program in python to display all values of given pandas series with first character in upper case. for example
Original Series is : 0 ravi 1 ram 2 sonu 3 david Expected Output : 0 Ravi 1 Ram 2 Sonu 3 David dtype: object
Ans. import pandas as pd S1 = pd.Series(["ravi", "ram", "sonu", "david"]) L = S1.values L1=[ ] for i in L: L1.append(i[0].upper() + i[1:]) S2 = pd.Series(L1) print(S2)
Q69. Write a program to display all odd numbers and its sum from the given Pandas Series.
0 15
1 2
2 8
3 4
4 1
5 25
6 30
Ans. import pandas as pd S1 = pd.Series([15, 2, 8, 4, 1, 25, 30]) print(S1[S1%2!=0]) S2=S1[S1%2!=0] print("Sum of all odd numbers is : ", sum(S2.values)) OUTPUT : 0 15 4 1 5 25 dtype: int64 Sum of all odd numbers is : 41
Q70. Write the output of the following :
import pandas as pd L=[1, 2] for i in range(25, 95, 10): L.append(i) S1 = pd.Series(L) print(S1)
Ans. 0 1 1 2 2 25 3 35 4 45 5 55 6 65 7 75 8 85 dtype: int64
Q71. Write the output of the following :
import pandas as pd
D = { }
for i in range(25, 95, 10):
D[i]=i+10
S1 = pd.Series(D)
print(S1)Ans. 25 35 35 45 45 55 55 65 65 75 75 85 85 95 dtype: int64
Q72. Write the output of the following :
import pandas as pd S1 = pd.Series(range(1, 20, 3)) print(S1)
Ans. 0 1 1 4 2 7 3 10 4 13 5 16 6 19 dtype: int64
Pandas Series Class 12 IP Important Questions
Disclaimer : I tried to give you the correct “Pandas Series Class 12 IP Important Questions” , but if you feel that there is/are mistakes in any question or answers of “Pandas Series Class 12 IP Important Questions” given above, you can directly contact me at csiplearninghub@gmail.com. Book and Study material available on CBSE official website is used as reference to create above “Pandas Series Class 12 IP Important Questions“
Important Points to Remember about Pandas Series
NumPy, Pandas and Matplotlib are Python libraries for scientific and analytical use. pip install pandas is the command to install Pandas library. A data structure is a collection of data values and the operations that can be applied to that data. It enables efficient storage, retrieval and modification to the data. Two main data structures in Pandas library are Series and DataFrame. To use these data structures, we first need to import the Pandas library. A Series is a one-dimensional array containing a sequence of values. Each value has a data label associated with it also called its index. The two common ways of accessing the elements of a series are Indexing and Slicing. There are two types of indexes: positional index and labelled index. Positional index takes an integer value that corresponds to its position in the series starting from 0, whereas labelled index takes any user-defined label as index When positional indices are used for slicing, the value at end index position is excluded, i.e., only (end - start) number of data values of the series are extracted. However with labelled indexes the value at the end index label is also included in the output. All basic mathematical operations can be performed on Series either by using the operator or by using appropriate methods of the Series object. While performing mathematical operations index matching is implemented and if no matching indexes are found during alignment, Pandas returns NaN so that the operation does not fail.
Class 12 Computer Science Sample Paper 2020-2021.
Class 12 Computer Science Sample Paper Marking Scheme
Class 12 Computer Science Chapter wise MCQ








