【发布时间】:2020-01-20 15:46:29
【问题描述】:
检查:
Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.isin.html
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.iteritems.html
我尝试做的是,基于一系列值采取不同的行动:
import pandas as pd
s = pd.Series([1,2,3, 4, 5, 6], name='number')
check_1 = ([1,2,3])
check_2 = ([4, 5, 6])
enter code here
不同的动作:
for index, value in s.items():
if s.isin([check_1]).any():
print('checked_1')
elif s.isin([check_2]).any():
print('checked_2')
else:
print ('nothing')
我得到的是:
nothing --> *should be checked_1*
nothing --> *should be checked_1*
nothing --> *should be checked_1*
nothing --> *should be checked_2*
nothing --> *should be checked_2*
nothing --> *should be checked_2*
【问题讨论】: