你想找到奇数 inedx ,但你真正要做的是找到奇数元素for i in lst: #(i ---->the element in lst) if i % 2 == 1:所以你应该试试这个for i in range(len(lst)): #( i ---> the index of lst) if i % 2 == 1:
2 回答
蓝山帝景
TA贡献1843条经验 获得超7个赞
pandas.Series实现了combine方法,您可以通过以下方式使用该方法来查找b也出现在a列表中的元素:
import pandas as pd
a = pd.Series([["a","b","c", "d"],["a","b","c", "d"],["a","b","c", "d"],["a","b","c", "d"],["a","b","c", "d"]])
b = pd.Series(["a","d","e", "c", "b"])
a.combine(b, lambda a,b: b in a)
输出:
0 True
1 True
2 False
3 True
4 True
dtype: object
交互式爱情
TA贡献1712条经验 获得超3个赞
这应该适合你:
import pandas as pd
a = pd.Series([["a","b","c", "d"],["a","b","c", "d"],["a","b","c", "d"],["a","b","c", "d"],["a","b","c", "d"]])
b = pd.Series(["a","d","e", "c", "b"])
[x in y for y,x in zip(a,b)]
...输出为:
[True, True, False, True, True]
添加回答
举报
0/150
提交
取消