В настоящее время я новичок в Python и работал над заданием по программированию, которое использует создание сводных таблиц из фреймов данных. Созданный мной фрейм данных показан ниже:
movieId title genres userId rating timestamp
0 1 Toy Story (1995) Adventure|Animation|Children|Comedy|Fantasy 2 3.5 1141415820
1 1 Toy Story (1995) Adventure|Animation|Children|Comedy|Fantasy 3 4.0 1439472215
2 1 Toy Story (1995) Adventure|Animation|Children|Comedy|Fantasy 4 3.0 1573944252
3 1 Toy Story (1995) Adventure|Animation|Children|Comedy|Fantasy 5 4.0 858625949
4 1 Toy Story (1995) Adventure|Animation|Children|Comedy|Fantasy 8 4.0 890492517
... ... ... ... ... ... ...
25000090 209157 We (2018) Drama 119571 1.5 1574280748
25000091 209159 Window of the Soul (2001) Documentary 115835 3.0 1574280985
25000092 209163 Bad Poems (2018) Comedy|Drama 6964 4.5 1574284913
25000093 209169 A Girl Thing (2001) (no genres listed) 119571 3.0 1574291826
25000094 209171 Women of Devil's Island (1962) Action|Adventure|Drama 119571 3.0 1574291937
25000095 rows × 6 columns
При попытке создать сводную таблицу со следующим кодом:
moviemat = df.pivot_table(index = 'userId', columns = 'title', values = 'rating')
я получаю следующую ошибку:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-20-68ffda9d9205> in <module>
----> 1 moviemat = df.pivot_table(index = 'userId', columns = 'title', values = 'rating')
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in pivot_table(self, values, index, columns, aggfunc, fill_value, margins, dropna, margins_name, observed)
6078 dropna=dropna,
6079 margins_name=margins_name,
-> 6080 observed=observed,
6081 )
6082
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\reshape\pivot.py in pivot_table(data, values, index, columns, aggfunc, fill_value, margins, dropna, margins_name, observed)
130 else:
131 to_unstack.append(name)
--> 132 table = agged.unstack(to_unstack)
133
134 if not dropna:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in unstack(self, level, fill_value)
6384 from pandas.core.reshape.reshape import unstack
6385
-> 6386 return unstack(self, level, fill_value)
6387
6388 _shared_docs[
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\reshape\reshape.py in unstack(obj, level, fill_value)
406 if isinstance(obj, DataFrame):
407 if isinstance(obj.index, MultiIndex):
--> 408 return _unstack_frame(obj, level, fill_value=fill_value)
409 else:
410 return obj.T.stack(dropna=False)
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\reshape\reshape.py in _unstack_frame(obj, level, fill_value)
436 value_columns=obj.columns,
437 fill_value=fill_value,
--> 438 constructor=obj._constructor,
439 )
440 return unstacker.get_result()
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\reshape\reshape.py in __init__(self, values, index, level, value_columns, fill_value, constructor)
139
140 self._make_sorted_values_labels()
--> 141 self._make_selectors()
142
143 def _make_sorted_values_labels(self):
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\reshape\reshape.py in _make_selectors(self)
174 selector = self.sorted_labels[-1] + stride * comp_index + self.lift
175 mask = np.zeros(np.prod(self.full_shape), dtype=bool)
--> 176 mask.put(selector, True)
177
178 if mask.sum() < len(self.index):
IndexError: index 993158425 is out of bounds for axis 0 with size 993157686
Кто-нибудь знает, почему я получаю эту ошибку и является ли она ошибкой в моем коде?