在系列字符串中应用lambda

时间:2019-06-17 02:54:24

标签: python python-3.x pandas

我试图将lambda函数用于一系列操作:

a = pd.Series(["The person was friendly and helpful",
           np.nan,
           "I enjoy using my Card.",
           np.nan,
           np.nan,
           "It is a nightmare to get the card activated"])

为我创建每个索引的双字母组,我发现很难应用lambda,因为它检测到该系列中的“ NaN”。在保留NaN索引以供以后合并时,有没有一种方法可以应用它或其他替代方法。

这是我的lambda:

a.apply(lambda x : re.findall(r'(?=(\b\w+\b \S+))', x) if x != "" else np.nan)

0 个答案:

没有答案