猿问

在python中比较1d和2d系列的有效方法

你想找到奇数 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:


杨魅力
浏览 216回答 2
2回答

蓝山帝景

pandas.Series实现了combine方法,您可以通过以下方式使用该方法来查找b也出现在a列表中的元素:import pandas as pda = 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     True1     True2    False3     True4     Truedtype: object

交互式爱情

这应该适合你:import pandas as pda = 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]
随时随地看视频慕课网APP

相关分类

Python
我要回答