Python Pandas — I — Question 12
Back to all questionsThree 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.
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)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
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