python中loc是什么

2023-12-13 15:53:15 网络知识 匿名

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培训机构:瀚银百科。

发表评论: