我有一个numpy数组,其中包含以下值: [10620.511899,11879.513017,11610.5]
import Numpy as np
array = np.array([10620.5, 11899, 11879.5, 13017, 11610.5])
我想得到“接近”的值(在本例中为11899和11879)并对它们进行平均,然后用新数字的单个实例替换它们,结果如下:
[10620.5, 11889, 13017, 11610.5]
术语“关闭”是可配置的。假设相差50
这样做的目的是在Bokah图上创建跨距,有些线太近了
一般来说,我对python非常陌生(几周的紧张开发)
我想我可以把这些值按顺序排列,然后把左边和右边的那一个取出来,对它们做一些数学计算,用平均值替换一个匹配项。但目前,我还不知道。你知道吗
尝试这样的方法,我添加了一些额外的步骤,只是为了显示流程: 其思想是将数据分组到相邻的组中,并根据它们的分布情况决定是否要对它们进行分组。你知道吗
因此,正如您所描述的,您可以将数据组合成3个数的集合,如果最大值和最小值之间的差值小于50,则取其平均值,否则保持原样。你知道吗
您可以在这里使用fuzzyfuzzy来衡量两个数据集之间的完备性比率。你知道吗
详见:http://jonathansoma.com/lede/algorithms-2017/classes/fuzziness-matplotlib/fuzzing-matching-in-pandas-with-fuzzywuzzy/
接受古斯塔沃的回答并根据我的需要进行调整:
如果我做了这样的事情:
其中烛台是我正在使用的主数据帧,supres\u df是另一个数据帧,我在将其应用到主数据帧之前正在对其进行按摩。你知道吗
它可以工作,但是非常慢。我现在正在尝试优化它。你知道吗
我添加了一个while循环,因为在平均之后,平均值可以变得足够接近再次平均,所以我将再次循环,直到不再需要平均为止。这是完全新手的工作,所以如果你看到一些愚蠢的,请评论。你知道吗
相关问题 更多 >
编程相关推荐