熊猫:检查A系列单词是否以B系列单词结尾的最快方法
发布于 2021-01-29 14:57:28
我想检查命名为Series的单词是否以Series的strings
一个单词结尾ending_strings
。
strings = Series(['om', 'foo_nom', 'nom', 'bar_foo', 'foo','blah'])
ending_strings = Series(['nom', 'foo'])
expected_results = Series([False, True, True, True, True, False])
我想出了以下代码,但是有没有更快或更更多的熊猫风格方式呢?
from pandas import Series
def ew(v):
return strings.str.endswith(v)
result = ending_strings.apply(ew).apply(sum).astype(bool)
result.equals(expected_results)
关注者
0
被浏览
67
1 个回答