Python Pandas (Series) Important Questions Answer
Exam Special Python Pandas Assignment
Que 21. If you do not explicitly specify an index for the data values while creating a series, what is the default value of the Series index?
Answer: By default, indices range from 0 to N – 1. Where N is the number of data elements of the Series.
Que 22. Which argument/parameter is used inside the Series() explicitly to specify an index for the data values while creating a series?
Answer: index
Que 23. Create a series having names of any five famous monuments of India and assign their States as index values.
Answer: Python Code-
import pandas as pd
monuments = pd.Series(['Taj Mahal', 'Lal Quila', 'Golden Temple', 'Qutub Minar','Konark Sun Temple'], index = ['UP', 'Delhi', 'Punjab', 'Delhi', 'Odisha'])
print(monuments)
Output:
Que 24. Create a series having the names of three students in your class and assign their roll numbers as index values.
Answer: Python Code-
import pandas as pd
student = pd.Series(['Neha', 'Rohit', 'Amrit'], index = [2, 6, 1])
print(student)
Output:
Que 25. Create a series having the month’s numbers as data and assign their name as index values.
Answer: Python Code-
import pandas as pd
month = pd.Series([2,5,9,10,1], index = ['Feb', 'May', 'Sep', 'Oct', 'Jan'])
print(month)
Output:
Que 26. Can you create a Series by using Dictionary? What happened if you create a series object using a dictionary?
Answer: Yes, we can create a series object using a dictionary.
Python dictionary has key: value pairs. Dictionary keys can be used to construct an index for a Series,
Que 27. Write a program to create a series object using a dictionary that stores the number of days in each month.
Answer: Python Code-
import pandas as pd
month = {'Jan': 31, 'Feb': 28, 'Mar' : 31, 'Apr' : 30}
mSeries = pd.Series(month)
print(mSeries)
Output:
Que 28. Write a program to create a series object using a dictionary that stores the number of students in each house of class 12D of your school.
Note: Assume four house names are Beas, Chenab, Ravi and Satluj having 18, 2, 20, 18 students respectively and pandas library has been imported as pd. [CBSE SQP]
Answer: Python Code-
import pandas as pd
house = {'Beas': 18, 'Chenab': 2, 'Ravi' : 20, 'Satluj' : 18}
serHouse = pd.Series(house)
print(serHouse)
Output:
Que 29. While importing Pandas, is it mandatory to always use pd as an alias name? What would happen if we give any other name?
Answer: No. If you give any other name, you have to use that name only at the time of using panda’s method.
Que 30. Write a program to create a series object using a one-dimensional numpy array (ndarray) storing the marks of 5 students.
Answer: Python Code-
import pandas as pd
import numpy as np
array1 = np.array([25,36,24,39,28])
series1 = pd.Series(array1)
print(series1)
Output: