Informatics Practices
Three Series objects store the marks of 10 students in three terms. Roll numbers of students form the index of these Series objects. The Three Series objects have the same indexes.
Calculate the total weighted marks obtained by students as per following formula :
Final marks = 25% Term 1 + 25% Term 2 + 50% Term 3
Store the Final marks of students in another Series object.
Python Pandas
3 Likes
Answer
import pandas as pd
term1 = pd.Series([80, 70, 90, 85, 75, 95, 80, 70, 85, 90], index=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
term2 = pd.Series([85, 90, 75, 80, 95, 85, 90, 75, 80, 85], index=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
term3 = pd.Series([90, 85, 95, 90, 80, 85, 95, 90, 85, 90], index=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
final_marks = (term1 * 0.25) + (term2 * 0.25) + (term3 * 0.50)
print(final_marks)Output
1 86.25
2 82.50
3 88.75
4 86.25
5 82.50
6 87.50
7 90.00
8 81.25
9 83.75
10 88.75
dtype: float64
Answered By
2 Likes
Related Questions
Consider the following DataFrame df and answer any four questions from (i)-(v):
rollno name UT1 UT2 UT3 UT4 1 Prerna Singh 24 24 20 22 2 Manish Arora 18 17 19 22 3 Tanish Goel 20 22 18 24 4 Falguni Jain 22 20 24 20 5 Kanika Bhatnagar 15 20 18 22 6 Ramandeep Kaur 20 15 22 24 Ms. Sharma, the class teacher wants to add a new column, the scores of Grade with the values, 'A', 'B', 'A', 'A', 'B', 'A' , to the DataFrame.
Help her choose the command to do so :
(a) df.column = ['A', 'B', 'A', 'A', 'B', 'A']
(b) df['Grade'] = ['A', 'B', 'A', 'A', 'B', 'A']
(c) df.loc['Grade'] = ['A', 'B', 'A', 'A', 'B', 'A']
(d) Both (b) and (c) are correct
Write a program that stores the sales of 5 fast moving items of a store for each month in 12 Series objects, i.e., S1 Series object stores sales of these 5 items in 1st month, S2 stores sales of these 5 items in 2nd month, and so on.
The program should display the summary sales report like this :
Total Yearly Sales, item-wise (should display sum of items' sales over the months) Maximum sales of item made : <name of item that was sold the maximum in whole year> Maximum sales for individual items Maximum sales of item 1 made : <month in which that item sold the maximum> Maximum sales of item 2 made : <month in which that item sold the maximum> Maximum sales of item 3 made : <month in which that item sold the maximum> Maximum sales of item 4 made : <month in which that item sold the maximum> Maximum sales of item 5 made : <month in which that item sold the maximum>Write code to print all the information about a Series object.
Write a program to create three different Series objects from the three columns of a DataFrame df.