繁体   English   中英

IndexError:使用熊猫数据时索引过多

[英]IndexError: too many indices when working with pandas data

编写了一个函数,该函数查找峰值并波谷信号,然后从名为mintab和maxtab的numpy库输出到两个ndarray对象,它们的索引是时间戳,其值是峰值。

我想将此数据绘制为散点图,其中时间戳记为x轴,峰值为y,所以我这样写:

xMax = maxtab[:,0]
yMax = maxtab[:,1]
xMin = mintab[:,0]
yMin = mintab[:,1]

mpl.rc('figure', figsize=(20, 2))                     # configure plot window size
plt.scatter(xMax, yMax, color='g', alpha=1)
plt.scatter(xMin, yMin, color= 'r', alpha = 1)

但是我不断收到错误消息: IndexError: too many indices ,指向行xMin = mintab[:,0]

我不明白为什么会这样,而且我在Google上找不到任何相关信息。

我很惊讶您没有收到无法散列的类型错误:

In [1]: df = pd.DataFrame([[1, 2], [3, 4]])

In [2]: df[:, 0]
# TypeError: unhashable type

如果要以这种方式选择0列,则应使用loc:

In [3]: df.loc[:, 0]
Out[3]:
0    1
1    3
Name: 0, dtype: int64

或直接选择列:

In [4]: df[0]
Out[4]:
0    1
1    3
Name: 0, dtype: int64

如果要指定第0列(与标签无关),请使用iloc:

In [5]: df.iloc[:, 0]
Out[5]:
0    1
1    3
Name: 0, dtype: int64

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM