Skip to content

Commit 0bca0a8

Browse files
committed
add day13 homework
1 parent 1776329 commit 0bca0a8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

D13_apply/homework.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pandas as pd
2+
import numpy as np
3+
# 對以下成績資料做分析
4+
5+
score_df = pd.DataFrame([[1,56,66,70], [2,90,45,34], [3,45,32,55], [4,70,77,89], [5,56,80,70], [6,60,54,55], [7,45,70,79], [8,34,77,76], [9,25,87,60], [10,88,40,43]],columns=['student_id','math_score','english_score','chinese_score'])
6+
print(score_df)
7+
8+
# 6 號學生(student_id=6) 3 科平均分數為何?
9+
noCol0 = np.delete(score_df.values,0,axis=1)
10+
# print('6 號學生(student_id=6) 3 科平均分數 %s' % noCol0.mean(axis=1)[5])
11+
df=score_df.drop(columns='student_id',axis=1)
12+
print('6 號學生(student_id=6) 3 科平均分數 %s' % df.values.mean(axis=1)[5])
13+
# 6 號學生 3 科平均分數是否有贏過班上一半的同學?
14+
print('中位數 %s' % df.mean(axis=1).median())
15+
if noCol0.mean(axis=1)[5] > df.mean(axis=1).median() :
16+
print('Yes, 6 號學生 3 科平均分數有贏過班上一半的同學')
17+
else:
18+
print('No, 6 號學生 3 科平均分數沒有贏過班上一半的同學')
19+
# 由於班上同學成績不好,所以學校統一加分,加分方式為開根號乘以十,請問 6 號同學 3 科成績分別是?
20+
newscore = df.apply(lambda x : x**(0.5)*10)
21+
print('加分後 6 號同學 3 科成績分別是')
22+
print(list(newscore.columns) )
23+
print(newscore.values[5])
24+
25+
# 承上題,加分後各科班平均變多少
26+
print('加分後各科班平均變多少 \n%s' % newscore.mean())

0 commit comments

Comments
 (0)