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