我的目标是获取数据帧的局部最大高度的索引。这些变化在每栏3至5之间。
我尝试过使用apply函数,但是得到了错误Shape of passed values is (736, 4), indices imply (736, 480)或could not broadcast input array from shape (0) into shape (1)。
我的矩阵是480x736。
下面是我为应用函数编写的内容:
import numpy as np
import peakutils
df.apply(lambda x: peakutils.indexes(x, thres=0.02/max(x), min_dist=100))以下是我能做的工作:
indexes =[]
import numpy as np
import peakutils
for column in df:
indexes.append(peakutils.indexes(df[column], thres=0.02/max(df[column]), min_dist=100))通常索引的长度为4,但偶尔我会得到1多或更少:
Out[32]:
[array([ 12, 114, 217, 328, 433]),
array([ 12, 116, 217, 325, 433]),
array([ 64, 166, 283, 389]),
array([105, 217, 326, 433]),
array([105, 237, 390])]我的猜测是,输出的问题来自于我不知道结果数据的形状。形状从一开始就无法确定。
如何将函数应用于输出大小和类型不同的df?
发布于 2016-10-13 19:23:00
熊猫正试图用数组“做些什么”。您可以通过将lambda的返回值封装在pd.Series中来缩短“某物”的短路。
试试这个:
df.apply(lambda x: pd.Series(peakutils.indexes(x, thres=0.02/max(x), min_dist=100)))https://stackoverflow.com/questions/40027612
复制相似问题