值的长度与索引的长度不匹配(提交报文)

时间:2018-12-03 14:56:05

标签: python pandas

我试图将计分的数据集合并到原始字段名称中,但出现错误:值的长度与索引的长度不匹配

有人知道这意味着什么吗?

这是此内核的我Kaggle网址: https://www.kaggle.com/jrichie/nyc-taxi-fare-eda-and-random-forest-model

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-48-2e0e7324d901> in <module>()
----> 1 submission['fare_amount'] = rf_predict

/opt/conda/lib/python3.6/site-packages/pandas/core/frame.py in __setitem__(self, key, value)
   3117         else:
   3118             # set column
-> 3119             self._set_item(key, value)
   3120 
   3121     def _setitem_slice(self, key, value):

/opt/conda/lib/python3.6/site-packages/pandas/core/frame.py in _set_item(self, key, value)
   3192 
   3193         self._ensure_valid_index(value)
-> 3194         value = self._sanitize_column(key, value)
   3195         NDFrame._set_item(self, key, value)
   3196 

/opt/conda/lib/python3.6/site-packages/pandas/core/frame.py in _sanitize_column(self, key, value, broadcast)
   3389 
   3390             # turn me into an ndarray
-> 3391             value = _sanitize_index(value, self.index, copy=False)
   3392             if not isinstance(value, (np.ndarray, Index)):
   3393                 if isinstance(value, list) and len(value) > 0:

/opt/conda/lib/python3.6/site-packages/pandas/core/series.py in _sanitize_index(data, index, copy)
   3999 
   4000     if len(data) != len(index):
-> 4001         raise ValueError('Length of values does not match length of ' 'index')
   4002 
   4003     if isinstance(data, ABCIndexClass) and not copy:

ValueError: Length of values does not match length of index

1 个答案:

答案 0 :(得分:0)

您可以找到答案here(非常常见的问题)

根据您的内核,看起来rf_predict数组有9824行,而submission数组有9914行。

相关问题