loc中的數(shù)據(jù)是列名,是字符串,所以前后都要取;iloc中數(shù)據(jù)是int整型,所以是Python默認(rèn)的前閉后開(kāi)loc函數(shù)
構(gòu)建數(shù)據(jù)集df
importpandasaspd
df=pd.DataFrame([
['green','M',10.1,'class1'],
['red','L',13.5,'class2'],
['blue','XL',15.3,'class1']])
print(df)
#數(shù)據(jù)集為以下內(nèi)容,所有操作均對(duì)df進(jìn)行
0123
0greenM10.1class1
1redL13.5class2
2blueXL15.3class1
loc函數(shù)主要通過(guò)行標(biāo)簽索引行數(shù)據(jù),劃重點(diǎn),標(biāo)簽!標(biāo)簽!標(biāo)簽!
loc[1]選擇行標(biāo)簽是1的(從0、1、2、3這幾個(gè)行標(biāo)簽中)
In[1]:df.loc[1]
Out[1]:0red
1L
213.5
3class2
以上內(nèi)容為大家介紹了python中l(wèi)oc是什么,希望對(duì)大家有所幫助,如果想要了解更多Python相關(guān)知識(shí),請(qǐng)關(guān)注IT培訓(xùn)機(jī)構(gòu):千鋒教育。