gpt4 book ai didi

python - 索引错误 : single positional indexer is out-of-bounds using pandas Series. from_csv

转载 作者:太空宇宙 更新时间:2023-11-03 14:22:06 25 4
gpt4 key购买 nike

我收到错误为

  File "C:/Users/Toshiba/PycharmProjects/untitled1/stationarity.py", line 7, in <module>

series = Series.from_csv('flowcaida.csv')

File "C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\series.py", line 2640, in from_csv

result = df.iloc[:, 0]

File "C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 1325, in __getitem__

return self._getitem_tuple(key)

File "C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 1662, in _getitem_tuple

self._has_valid_tuple(tup)
File "C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 189, in _has_valid_tuple

if not self._has_valid_type(k, i):

File "C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 1597, in _has_valid_type
return self._is_valid_integer(key, axis)

File "C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 1638, in _is_valid_integer

raise IndexError("single positional indexer is out-of-bounds")

IndexError: single positional indexer is out-of-bounds

使用这个:

series = Series.from_csv('flowcaida.csv')

这是我的数据:

651680

459151

596299

474950

631421

465275

629861

455582

650192

感谢您的帮助。

最佳答案

Series.from_csv 已被弃用很长一段时间了。您应该使用read_csv反而。

由于您有单列 CSV,因此您可以传递 squeeze=True 以便返回 Series

s = pd.read_csv(buf, header=None, names=["Data"], squeeze=True)
s

0 651680
1 459151
2 596299
3 474950
4 631421
5 465275
6 629861
7 455582
8 650192
Name: Data, dtype: int64

type(s)
pandas.core.series.Series

关于python - 索引错误 : single positional indexer is out-of-bounds using pandas Series. from_csv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47873836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com