隨機抽樣
import pandas as pd
#對dataframe隨機抽取2000個樣本
pd.sample(df, n=2000)
分層抽樣
利用sklean中的函數靈活進行抽樣
from sklearn.model_selection import train_test_split
#y是在X中的某一個屬性列
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2, stratify=y)