小编use*_*847的帖子

类型错误:无法解包不可迭代的 int 对象

我如何解决这个错误运行我的代码如下。我正在使用下面的函数并在运行窗口中实现循环,但最终得到以下错误。for 循环起作用并挂在某个点上。

def get_grps(s, thresh=-1, Nmin=3):
    """
    Nmin : int > 0
    Min number of consecutive values below threshold.
    """
    m = np.logical_and.reduce([s.shift(-i).le(thresh) for i in range(Nmin)])
    if Nmin > 1:
        m = pd.Series(m, index=s.index).replace({False: np.NaN}).ffill(limit=Nmin - 1).fillna(False)
    else:
        m = pd.Series(m, index=s.index)

    # Form consecutive groups
    gps = m.ne(m.shift(1)).cumsum().where(m)

    # Return None if no groups, else the aggregations
    if gps.isnull().all():
        return 0
    else:
        agg = s.groupby(gps).agg([list, sum, 'size']).reset_index(drop=True)
        # agg2 = s2.groupby(gps).agg([list, sum, 'size']).reset_index(drop=True)
        return agg, gps


data_spi = …
Run Code Online (Sandbox Code Playgroud)

python numpy scipy pandas python-xarray

5
推荐指数
2
解决办法
8万
查看次数

在python中一次跳过列表的特定范围

我有一个数组,我想选择前 2 个或范围,跳过下一个 2,选择下一个 2,然后继续直到列表末尾

list = [2, 4, 6, 7, 9,10, 13, 11, 12,2]
results_wanted = [2,4,9,10,12,2] # note how it skipping 2. 2 is used here as and example
Run Code Online (Sandbox Code Playgroud)

有没有办法在Python中实现这一点?

python numpy python-xarray

5
推荐指数
2
解决办法
308
查看次数

找到超过特定阈值的概率

我有一个长度为 324 的数组。我试图根据数组中的值找到超过特定阈值的概率

我努力了::

data = [3,4, 5, 1, 5, 8, 9] ## sample

p = 100 * (4/(len(data)+1)) ## where 4 is my threshold. 
Run Code Online (Sandbox Code Playgroud)

我不确定这是否正确,是否有更好的方法?

python probability

1
推荐指数
1
解决办法
1180
查看次数

标签 统计

python ×3

numpy ×2

python-xarray ×2

pandas ×1

probability ×1

scipy ×1