为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

杨魅力 2021-12-09 10:59:12
你想找到奇数 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


查看完整回答
反对 回复 2021-12-09
?
交互式爱情

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]


查看完整回答
反对 回复 2021-12-09
  • 2 回答
  • 0 关注
  • 215 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信