pandas的索引对象可以用来保存坐标轴标签和其他元数据,这是使用过程中必不可少的参与对象。pandas中的index索引功能是什么?pandas中的index索引可以轻松读取数据,更方便查询数据,使用index查询可以提高性能。
Index索引的特点
使用index查询时,更方便的数据查询可以获得性能提升;
自动数据对齐功能;
数据结构支持越来越强。
二、index索引用途
1、使用index读取数据
importpandasaspd df=pd.read_csv("./datas/ml-latest-small/ratings.csv") df.count()#记录每列数量
2、使用index查询数据
#drop==False,让索引列仍然保持在column df.set_index("userId",inplace=True,drop=False) df.head() df.index 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 ... 610,610,610,610,610,610,610,610,610,610,610 dtype='int64',name='userId',length=100836) #使用index的查询方法 df.loc[500].head(5)
以上就是pandasindex索引的相关介绍,希望能帮助您理解哟~更多python学习推荐:python教程。
(推荐操作系统:windows7系统Python 3.9.1,DELL G3电脑。)