np.r_的用法

pandas 中有时需要分段选择数据,可以用如下方法:

# 读取前1~20行以及48、49行的数据 (note: pandas 的行标签从0开始)
ind = list(range(20)) + list([47,48])
df.iloc[ind]

另一种方法是用np.r_,更为方便:

np.r_[:20, 47:49]
## output
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19, 47, 48])

猜你喜欢

转载自blog.csdn.net/guo_ya_nan/article/details/81015914