loc中的數(shù)據(jù)是列名,是字符串,所以前后都要取;iloc中數(shù)據(jù)是int整型,所以是Python默認的前閉后開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)容,所有操作均對df進行
0123
0greenM10.1class1
1redL13.5class2
2blueXL15.3class1
loc函數(shù)主要通過行標簽索引行數(shù)據(jù),劃重點,標簽!標簽!標簽!
loc[1]選擇行標簽是1的(從0、1、2、3這幾個行標簽中)
In[1]:df.loc[1]
Out[1]:0red
1L
213.5
3class2
以上內(nèi)容為大家介紹了python中l(wèi)oc是什么,希望對大家有所幫助,如果想要了解更多Python相關(guān)知識,請關(guān)注IT培訓(xùn)機構(gòu):千鋒教育。