'Shape of passed values is x, indices imply y'熊猫适用



我有这段代码:

def feat_ext_nir(x):
    img = loadImage(x['image_name'])
    compressed_img = compress_image(16, 16, img[:,:,3])
    return compressed_image.ravel()
cloud_feat_nir = cloud_df_samp.apply(feat_ext_nir, axis=1)
cloud_feat_nir.describe()

当我执行时,我收到此错误:

ValueError: Shape of passed values is (2000, 256), indices imply (2000, 5)

应用函数应该返回一个新的数据帧。它从旧数据帧 (cloud_df_samp( 获取的唯一信息是"image_name"列。256 是应该返回的正确列数,但它似乎认为该数字应该与 cloud_df_samp (5( 中的列数相同,我不确定为什么。

谁能告诉我为什么它需要 5 列或我应该采取不同的做法?完整的错误跟踪是:

ValueError: Shape of passed values is (2000, 256), indices imply (2000, 5)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/pandas/core/internals.py in 
create_block_manager_from_arrays(arrays, names, axes)
   4262         blocks = form_blocks(arrays, names, axes)
-> 4263         mgr = BlockManager(blocks, axes)
   4264         mgr._consolidate_inplace()
/opt/conda/lib/python3.6/site-packages/pandas/core/internals.py in 
__init__(self, blocks, axes, do_integrity_check, fastpath)
   2760         if do_integrity_check:
-> 2761             self._verify_integrity()
   2762 
/opt/conda/lib/python3.6/site-packages/pandas/core/internals.py in 
_verify_integrity(self)
   2970             if block._verify_integrity and block.shape[1:] != 
mgr_shape[1:]:
-> 2971                 construction_error(tot_items, block.shape[1:], 
self.axes)
   2972         if len(self.items) != tot_items:
/opt/conda/lib/python3.6/site-packages/pandas/core/internals.py in 
construction_error(tot_items, block_shape, axes, e)
   4232     raise ValueError("Shape of passed values is {0}, indices imply 
{1}".format(
-> 4233         passed, implied))
   4234 
ValueError: Shape of passed values is (2000, 256), indices imply (2000, 5)
During handling of the above exception, another exception occurred:
ValueError                                Traceback (most recent call last)
<ipython-input-15-c473d99817c3> in <module>()
  4     return compressed_image.ravel()
  5 
----> 6 cloud_feat_nir = cloud_df_samp.apply(feat_ext_nir, axis=1)
      7 cloud_feat_nir.describe()
/opt/conda/lib/python3.6/site-packages/pandas/core/frame.py in apply(self, 
func, 
axis, broadcast, raw, reduce, args, **kwds)
这是我在

黑暗中拍摄的东西,因为我不确定输入数据的细节,但是这段代码是否如您所愿?

def feat_ext_nir(x):
    img = loadImage(x['image_name'])
    compressed_img = compress_image(16, 16, img[:,:,3])
    return compressed_image.ravel().tolist()
cloud_feat_nir = pd.Series(cloud_df_samp.apply(feat_ext_nir, axis=1))
cloud_feat_nir.describe()

最新更新