資料選擇與篩選
欄位選擇 (columns),只需要表內的特定幾欄
數值篩選,只需要滿足篩選條件的資訊
.loc、.iloc
df_straw_hat['name']
type(df_straw_hat['name'])
df_straw_hat[['name', 'gender']]
type(df_straw_hat[['name', 'occupation']])
lis_filter = [True, True, True, True, True, False, False, False, False]
df_straw_hat[lis_filter]
df_straw_hat['gender'] == 'male'
df_straw_hat[df_straw_hat['gender'] == 'male']
df_straw_hat[(df_straw_hat['gender'] == 'male') &
(df_straw_hat['age'] <= 20)]
df_straw_hat[(df_straw_hat['gender'] == 'female') |
(df_straw_hat['age'] <= 20)]
df_straw_hat.loc[0,'name']
df_straw_hat.loc[0:3,'name']
df_straw_hat.loc[0:3,'name':'age']
df_straw_hat.loc[[0,2,4],['name','age']]
df_straw_hat.loc[:,:]
df_straw_hat.iloc[0,0]
df_straw_hat.iloc[0:3,0]
df_straw_hat.iloc[0:3,0:3]
df_straw_hat.iloc[[0,2,4],[0,2]]
df_straw_hat.iloc[:,:]
使用pandas篩選出特定條件的成員吧
在df_straw_hat中,一次篩選出[身高175以下的男生]或[身高180以上的女生]
&、|的混合使用
每一個條件式記得使用小括號包起來再連接