This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 取得 grouped2 中,1A 班級學生中,分數為 95 這個分組中,學生的資料。 | |
grouped2.get_group(('1A', 95)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 取得 Peter 這位學生的所有的資料 | |
g1a.loc[g1a.name == 'Peter', :] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 取得 1A 班級中的學生,其 row label 為 1 的這位學生的資料 | |
g1a.loc[1,:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 取得 1A 的分組資料 | |
g1a = grouped.get_group('1A') | |
g1a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#依照 class 以及 math 這兩個類別來分類,第一階是使用 class 的類別來分類,接著使用 math 的分數來分類 | |
grouped2 = students.groupby(['class', 'math']) | |
grouped2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#依照 class 中的類別來分組 | |
grouped = students.groupby('class') | |
grouped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
#準備資料 | |
classes = ['1A', '1A', '1A', '1B', '1B', '1C', '1C', '1C'] | |
name = ['Peter', 'John', 'Keven', 'JoJo', 'Mary', 'Eva', 'Tom', 'Simon'] | |
math = [95, 95, 76, 90, 96, 84, 84, 98] | |
english = [64,88,85,88,78,60,63, 84] | |
tmpdic = {'class':classes, 'name':name, 'math':math, 'english':english} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#以百分比秀資料,並排序結果 | |
gapdf.continent.value_counts(normalize=True, ascending=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#以百分比的方式呈現結果 | |
gapdf.continent.value_counts(normalize=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#在 gapdf 這個 dataframe 的 continent 欄位上做 value_counts() 的動作 | |
gapdf.continent.value_counts() |