Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 有时,pd.Series.isin是可调用的,有时引发Series对象不可调用的异常_Python 3.x_Pandas - Fatal编程技术网

Python 3.x 有时,pd.Series.isin是可调用的,有时引发Series对象不可调用的异常

Python 3.x 有时,pd.Series.isin是可调用的,有时引发Series对象不可调用的异常,python-3.x,pandas,Python 3.x,Pandas,下面的代码抛出一个Series对象is callable异常。我添加了一个测试来查看isin方法是否可调用:它按预期返回True。但我还是有一个例外: ``` 哪些产出: Processing data/tysonl.2018-05-23-prod-quilt-status.csv **<class 'method'> True** ---------------------------------------------------------------------------

下面的代码抛出一个Series对象is callable异常。我添加了一个测试来查看isin方法是否可调用:它按预期返回True。但我还是有一个例外: ```

哪些产出:

Processing data/tysonl.2018-05-23-prod-quilt-status.csv
**<class 'method'> True**

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-70-235b583cc64f> in <module>()
     21         assert isinstance( owners, pd.core.series.Series), "Tried to convert owners to a Series and failed"
     22     print(type(owners.isin), callable(owners.isin))
---> 23     ours=owners.isin(managers)
     24     # assert df_date not in index_lst, f"df_date {df_date} is already in the index_lst\n{index_lst}\nfilename is {filename}."
     25     if dt_date not in index_lst:

/usr/local/lib/python3.6/dist-packages/pandas/core/series.py in isin(self, values)
   2802         """
   2803         result = algorithms.isin(_values_from_object(self), values)
-> 2804         return self._constructor(result, index=self.index).__finalize__(self)
   2805 
   2806     def between(self, left, right, inclusive=True):

TypeError: 'Series' object is not callable
```
正如所料

我无法在jupyter之外重现这个问题

我是熊猫新手。我也是个新手。我有点喜欢jupyter,但是如果我要出现这些奇怪的错误,那么我必须重新使用pycharm,这并不坏。我不知道还有什么其他信息可能有用,或者应该寻找什么。特别是,我完全无法理解为什么可调用(owner.isin),但引发了异常


谢谢你

你没有指出什么是
管理者
,或者它是什么来源。管理者是一个字符串列表。
Processing data/tysonl.2018-05-23-prod-quilt-status.csv
**<class 'method'> True**

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-70-235b583cc64f> in <module>()
     21         assert isinstance( owners, pd.core.series.Series), "Tried to convert owners to a Series and failed"
     22     print(type(owners.isin), callable(owners.isin))
---> 23     ours=owners.isin(managers)
     24     # assert df_date not in index_lst, f"df_date {df_date} is already in the index_lst\n{index_lst}\nfilename is {filename}."
     25     if dt_date not in index_lst:

/usr/local/lib/python3.6/dist-packages/pandas/core/series.py in isin(self, values)
   2802         """
   2803         result = algorithms.isin(_values_from_object(self), values)
-> 2804         return self._constructor(result, index=self.index).__finalize__(self)
   2805 
   2806     def between(self, left, right, inclusive=True):

TypeError: 'Series' object is not callable
```
jeffs@jeffs-desktop:/home/jeffs/learn_pandas (development) *  $ python3
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
>>> s = pd.Series(['lama', 'cow', 'lama', 'beetle', 'lama','hippo'], name='animal')
>>> s.isin(['cow'])
0    False
1     True
2    False
3    False
4    False
5    False
Name: animal, dtype: bool
>>> 
jeffs@jeffs-desktop:/home/jeffs/learn_pandas (development) *  $ ipython
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.3.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import sys

In [2]: print(sys.version)
3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0]

In [3]: import pandas

In [4]: import pandas as pd

In [5]: s = pd.Series(['lama', 'cow', 'lama', 'beetle', 'lama','hippo'], name='animal')

In [6]: s.isin(['cow'])

Out[6]: 
0    False
1     True
2    False
3    False
4    False
5    False
Name: animal, dtype: bool

In [7]: