Следующий код выдает объект Series для вызываемого исключения.Я добавил тест, чтобы проверить, может ли метод isin вызываться: он возвращает True, как и ожидалось.Но я все еще получаю это исключение: `` `
data = {}
index_lst = []
our_lst = []
their_lst = []
for filename in glob.glob('data/tysonl.2018-05-2*.csv'):
# filename = f"fred_2018-05-0{m}.csv"
print(f"Processing {filename}")
mpd = pd.read_csv(filename, usecols=['Date', 'hostname', 'primary owner', 'status'])
# This is from
# https://stackoverflow.com/questions/28133018/convert-pandas-series-to-datetime-in-a-dataframe
datetime.date: df_date = pd.to_datetime(mpd["Date"]).dt.date[0]
pd.core.series.Series: hostnames = mpd.hostname
pd.core.series.Series: statuses = mpd.status
pd.core.series.Series: owners = mpd['primary owner'] # Space in column name means has to be an index[] not attribute
# I don't know why, but sometimes read_csv returns a numpy.ndarray in column primary owner. It happens in some CSV
# files and not others. So I am doing this "hail Mary" conversion.
if type(owners)!=type(pd.core.series.Series):
print( f"owners should be of type pandas.core.series.Series but are actually {type(primary_owners)}. Converting")
pd.core.series.Series: owners = pd.Series( primary_owners )
assert isinstance( owners, pd.core.series.Series), "Tried to convert owners to a Series and failed"
print(type(owners.isin), callable(owners.isin)))
ours=owners.isin(managers)
, который выводит:
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
```
Это сводит меня с ума, что он вызывается на линии перед вызовом .isin, и все жеПитон думает, что это не вызывается и вызывает исключение.Я попытался воспроизвести проблему в меньшей, более сжатой среде, и я был неспособен сделать это.
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]:
Также, как и ожидалось.
Я не могу воспроизвести проблему вообще за пределамиjupyter.
Я новичок в пандах.Я также новичок Юпитера.Я вроде как jupyter, но если у меня будут такие странные ошибки, я должен вернуться к использованию pycharm, что не так уж и плохо.Я понятия не имею, какая другая информация может быть полезна или что искать.В частности, я совершенно не понимаю, почему вызывается (owners.isin), но возникает исключение.
Спасибо