<jupyter_start><jupyter_text>作業目標:1. 熟悉分組計算 作業重點: 1. 分組計算也可以加入apply自定義的函數 題目 : 運用下列分數資料分析1. 找出全年級各科成績最高分與最低分?2. 找出數學班平均最高的班級?3. 分析全校女生與男生國文平均差幾分?score_df = pd.DataFrame([[1,50,80,70,'boy',1],[2,60,45,50,'boy',2],[3,98,43,55,'boy',1],[4,70,69,89,'boy',2],[5,56,79,60,'girl',1],[6,60,68,55,'girl',2],[7,45,70,77,'girl',1],[8,55,77,76,'girl',2],[9,25,57,60,'girl',1],[10,88,40,43,'girl',3],[11,25,60,45,'boy',3],[12,80,60,23,'boy',3],[13,20,90,66,'girl',3],[14,50,50,50,'girl',3],[15,89,67,77,'girl',3]],columns=['student_id','math_score','english_score','chinese_score','sex','class'])<jupyter_code>import pandas as pd
score_df = pd.DataFrame([[1,50,80,70,'boy',1], 
              [2,60,45,50,'boy',2],
              [3,98,43,55,'boy',1],
              [4,70,69,89,'boy',2],
              [5,56,79,60,'girl',1],
              [6,60,68,55,'girl',2],
              [7,45,70,77,'girl',1],
              [8,55,77,76,'girl',2],
              [9,25,57,60,'girl',1],
              [10,88,40,43,'girl',3],
              [11,25,60,45,'boy',3],
              [12,80,60,23,'boy',3],
              [13,20,90,66,'girl',3],
              [14,50,50,50,'girl',3],
              [15,89,67,77,'girl',3]],columns=['student_id','math_score','english_score','chinese_score','sex','class'])
score_df
#1.找出全年級各科成績最高分與最低分?

score_df.iloc[:, 1:4].agg(['max','min']) 
#2.找出數學班平均最高的班級?

#方法1 
score_df.iloc[:,[1,5]].groupby('class').mean().idxmax()
#方法2
score_df.iloc[:,[1,5]].groupby('class').mean()<jupyter_output><empty_output><jupyter_text>Class 2 數學平均最高，平均 61.25分<jupyter_code>#方法3
score_df.groupby('class')['math_score'].mean().idxmax()
#3.分析全校女生與男生國文平均差幾分?

import numpy as np
import pandas as pd
np.abs(score_df.groupby('sex').mean()['chinese_score'][0] - score_df.groupby(['sex']).mean()['chinese_score'][1])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2722772277227723, 'fraction_numerical': 0.15181518151815182, 'mean_word_length': 5.294117647058823, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '440641', 'license': 'CC0-1.0', 'n_tokens_mistral': 1023, 'n_tokens_neox': 952, 'n_words': 54, 'path': 'homework/16 Homework_Melissa.ipynb', 'repo_name': 'melissa0520/ML100Days', 'size': '1818'}