作品:
import sympy as sp
import pandas as pd
test = pd.DataFrame( {'greeting':['hey','hi','hello','howdy']} )
test1['greeting'].map(lambda x: sp.Set(*x).is_proper_subset( sp.Set(*x) ))
不起作用:
import sympy as sp
import pandas as pd
test = pd.DataFrame( {'greeting':['hey','hi','hello','howdy']} )
test1['greeting'].map(lambda x: sp.Set('hi',).is_proper_subset( sp.Set(*x) ))```
我得到:
AttributeError: 'str' object has no attribute 'args'
我还尝试过在另一个数据帧上使用数字:
test['triplets'].map(lambda x: sp.Set(*(813,)).is_proper_subset( sp.Set(*x) ))
我得到了同样的结果。
https://docs.sympy.org/latest/modules/sets.html
class sympy.sets.sets.Set(*args)[source]¶
The base class for any kind of set.
好的。。。为什么当我通过lambda传递它时,它对每个Series值都有效,而当我手动编写时却无效
注意:我的最终目标是在一个for循环中,迭代被传递到我有"hi"的地方
来自sympy的Set
文档:
类sympy.sets.sets.Set(*args([source]¶这并不意味着要直接用作物品的容器。它的行为与内置集不同;请参见FiniteSet。
主要问题是CCD_ 4是指区间类型的"0";集合";。它似乎不能很好地处理更简单的集合,但给出了一个相当神秘的错误消息。在调试时,它通常有助于尽可能减少问题:
import sympy as sp
sp.Set(1, 2).is_proper_subset(sp.Set(1, 2, 3))
这会引发错误AttributeError: 'int' object has no attribute 'args'
。
类似:
sp.Set('a', 'b').is_proper_subset(sp.Set('a', 'b', 'c'))
导致AttributeError: 'str' object has no attribute 'args'
。
原始问题的最佳解决方案是使用标准的python函数。
我不知道交易是什么,我希望有一个答案,但在那之前,我只能求助于
test1['greeting'].map(lambda x: set('hi').issubset(set(x)) and set('hi')!=set(x))