2019-03-25
阅读量:
486
如何使用Pandas中的标签进行索引
可以使用pandas.DataFrame.loc方法对标签进行索引,该函数允许使用标签而不是位置进行索引。
例子:
# prints first five rows including 5th index and every columns of df
df.loc[0:5,:]
# prints from 5th rows onwards and entire columns
df = df.loc[5:,:]
以上实际上与df.iloc [0:5,:]没什么不同。这是因为虽然行标签可以采用任何值,但我们的行标签与位置完全匹配。






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论