0

I am trying to merge a scored dataset into the original field name and I get the error: Length of values does not match length of index

Does anyone know what this one means?

here is my Kaggle URL for this Kernel: 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
  • It's a pretty literal error. It's saying that you're trying to merge **n** values onto an index that can only support exactly **m** indices -where **m** != **n**. Try checking out which values you're missing or erroneously including. – Brian Dec 03 '18 at 15:26

1 Answers1

0

You can find the answer here (pretty common question)

Based on your kernel, it looks like your rf_predict array has 9824 rows whereas your submission array has 9914 entries.

Beinje
  • 572
  • 3
  • 18