Python'只能比较带有相同标签的Series对象'

时间:2017-12-08 22:31:18

标签: python object jupyter series

我希望在我的csv文件中附加一个列,它在csv中迭代,然后从另一个csv接收符号的计数并将其附加到相应的行。

#created the function that takes the input of the symbol passed 
def data_count(passed):

    x = prices.loc[(prices.symbol == 'A', 'close')].count()
    return(x)

securities['data freq'] == data_count(securities['Ticker symbol'])
securities

我认为问题是x = prices.loc[(prices.symbol == 'A', 'close')].count(),特别是我认为问题可能与'A'比较有关。

我想将A替换为它从迭代表中获得的变量,但是当我尝试这样做时,我的代码会抛出以下错误:

  

ValueError:只能比较带有相同标签的Series对象

非常感谢任何帮助。谢谢!

响应:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-77-718d2fbf3ad8> in <module>()
      5     return(x)
      6 
----> 7 securities['data freq'] == data_count(securities['Ticker symbol'])
      8 securities

<ipython-input-77-718d2fbf3ad8> in data_count(passed)
      2 def data_count(passed):
      3     data = [passed]
----> 4     x = (prices.loc[(prices.symbol == passed, 'close')].count())
      5     return(x)
      6 

/opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in wrapper(self, other, axis)
    816             if not self._indexed_same(other):
    817                 msg = 'Can only compare identically-labeled Series objects'
--> 818                 raise ValueError(msg)
    819             return self._constructor(na_op(self.values, other.values),
    820                                      index=self.index, name=name)

ValueError: Can only compare identically-labeled Series objects

0 个答案:

没有答案