天天看點

df.loc用法

df.loc[行标簽,列标簽]

df.loc['a':'b']#選取ab兩行資料

df.loc[:,'one']#選取one列的資料
           

示例代碼

df.loc[ (df.Cabin.notnull()), 'Cabin' ] = "Yes"
           

上一行代碼的意思是:選取Cabin列中不為空的位置替換為“Yes”