Skip to content

Instantly share code, notes, and snippets.

View justimchung's full-sized avatar

鍾毓驥 justimchung

View GitHub Profile
# 取得 grouped2 中,1A 班級學生中,分數為 95 這個分組中,學生的資料。
grouped2.get_group(('1A', 95))
# 取得 Peter 這位學生的所有的資料
g1a.loc[g1a.name == 'Peter', :]
# 取得 1A 班級中的學生,其 row label 為 1 的這位學生的資料
g1a.loc[1,:]
# 取得 1A 的分組資料
g1a = grouped.get_group('1A')
g1a
#依照 class 以及 math 這兩個類別來分類,第一階是使用 class 的類別來分類,接著使用 math 的分數來分類
grouped2 = students.groupby(['class', 'math'])
grouped2
#依照 class 中的類別來分組
grouped = students.groupby('class')
grouped
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}
@justimchung
justimchung / value_counts3.py
Created August 26, 2019 07:55
Value_counts
#以百分比秀資料,並排序結果
gapdf.continent.value_counts(normalize=True, ascending=True)
@justimchung
justimchung / value_counts2.py
Created August 26, 2019 07:51
Use value counts to show the data in a dataframe
#以百分比的方式呈現結果
gapdf.continent.value_counts(normalize=True)
@justimchung
justimchung / value_counts.py
Last active August 26, 2019 07:48
Use value_counts to show the data in the Gapminder dataset.
#在 gapdf 這個 dataframe 的 continent 欄位上做 value_counts() 的動作
gapdf.continent.value_counts()