ValueError:传递值的形状是(1,31),索引暗示(1,32)

时间:2017-05-17 17:07:58

标签: python pandas

我收到此错误:

 ValueError: Shape of passed values is (1, 31), indices imply (1, 32)

在此功能中:

def compute_r_statistic(x):
    R_stat = np.zeros(shape=(0,0))
    x = x[np.logical_not(np.isnan(x))]
    sample = x
    for i in range(0,len(x)):
        avg = np.nanmean(sample)
        std = np.nanstd(sample)
        sample = np.fabs(sample - avg)
        **print sample[0].argmax()**
        r_i = np.max(sample)/std
        R_stat = np.append(R_stat,r_i)
        #remove biggest value
        sample = np.delete(sample, -1)
    return R_stat

在这一行:

print sample[0].argmax()

如何打印argmax?

x是像这样的pandas数据框:

>>> print x
                    0
1951-03-31        NaN
1951-06-30        NaN
1951-09-30   7.918750
1951-12-31   6.936607
1952-03-31  34.029464
1952-06-30  -4.672321
1952-09-30 -15.85625

1 个答案:

答案 0 :(得分:1)

尝试chaning:

class Product extends Model
{
    // ...

    public function account()
    {
        return $this->hasManyThrough(Account::class, Channel::class);
    }
}

class Category extends Model
{
    public function channel()
    {
        return $this->belongsToMany(Channel::class);
    }
}

print sample[0].argmax()

看它是否有帮助?