Я пытаюсь записать фрейм данных в CSV-файл.
когда я запускаю эту команду df.to_csv("somefile.csv")
.
Я получаю ошибку ниже:
IndexError: индекс 14285 выходит за границы оси 0 с размером 14285
Я проверил длину индекса и данных, оба одинаковы.
df = pd.DataFrame(preds,columns = ['PA','PB','PC','PD','PE','PF','PG'], index =[X_valid_full['ID']])
len(preds)
len(X_valid_full['ID'].unique())
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-69-4113bef3e95d> in <module>
----> 1 df.to_csv("somefile.csv")
c:\users\appdata\local\programs\python\python37\lib\site-packages\pandas\core\generic.py in to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, line_terminator, chunksize, tupleize_cols, date_format, doublequote, escapechar, decimal)
3018 doublequote=doublequote,
3019 escapechar=escapechar, decimal=decimal)
-> 3020 formatter.save()
3021
3022 if path_or_buf is None:
c:\users\appdata\local\programs\python\python37\lib\site-packages\pandas\io\formats\csvs.py in save(self)
170 self.writer = UnicodeWriter(f, **writer_kwargs)
171
--> 172 self._save()
173
174 finally:
c:\users\appdata\local\programs\python\python37\lib\site-packages\pandas\io\formats\csvs.py in _save(self)
286 break
287
--> 288 self._save_chunk(start_i, end_i)
289
290 def _save_chunk(self, start_i, end_i):
c:\users\appdata\local\programs\python\python37\lib\site-packages\pandas\io\formats\csvs.py in _save_chunk(self, start_i, end_i)
313
314 libwriters.write_csv_rows(self.data, ix, self.nlevels,
--> 315 self.cols, self.writer)
pandas\_libs\writers.pyx in pandas._libs.writers.write_csv_rows()
IndexError: index 14285 is out of bounds for axis 0 with size 14285