与Series不兼容的索引器

时间:2013-12-25 11:30:17

标签: pandas

为什么我会收到错误:

import pandas as pd
a = pd.Series(index=[4,5,6], data=0)
print a.loc[4:5]
a.loc[4:5] += 1

输出:

4    0
5    0
Traceback (most recent call last):
  File "temp1.py", line 9, in <module>
dtype: int64
    a.loc[4:5] += 1
  File "lib\site-packages\pandas\core\indexing.py", line 88, in __setitem__
    self._setitem_with_indexer(indexer, value)
  File "lib\site-packages\pandas\core\indexing.py", line 177, in _setitem_with_indexer
    value = self._align_series(indexer, value)
  File "lib\site-packages\pandas\core\indexing.py", line 206, in _align_series
    raise ValueError('Incompatible indexer with Series')
ValueError: Incompatible indexer with Series

熊猫0.12。

1 个答案:

答案 0 :(得分:4)

我认为这是一个错误,你可以通过使用元组索引来解决这个问题:

import pandas as pd
a = pd.Series(index=[4,5,6], data=0)
print a.loc[4:5]
a.loc[4:5,] += 1