【发布时间】:2021-12-28 14:32:54
【问题描述】:
我有一个 pandas 数据框,如下所示:
email col2 col3
email@example.com John Doe
xxxemail@example.com John Doe
xxemail@example.com John Doe
xxxxxemail@example.com John Doe
xxxemail@example2.com Jane Doe
我想检查以至少两个“x”开头的每个电子邮件地址,并检查是否存在没有这些“x”的相同电子邮件地址。
要求的结果:
email col2 col3 exists_in_valid_form
email@example.com John Doe False
xxxemail@example.com John Doe True
xxemail@example.com John Doe True
xxxxxemail@example.com John Doe True
xxxemail@example2.com Jane Doe False
我能够使用df[df['email'].str.contains("xx")] 获得包含所有以“xx”开头的电子邮件的行的子数据框,并且还能够使用str.lstrip('x') 获得没有“x”的电子邮件地址,但是两者似乎都不能帮助我了解这封电子邮件是否出现在没有这些 x 的其他地方。
【问题讨论】:
-
我认为使用 str.lstrip('x') 也会去除电子邮件中单词 example 中的 x。我想在这种情况下它仍然可以工作,因为它会从所有内容中删除,但可能会导致实际数据出现问题
-
@EmiOB 我验证了一旦下一个字符不是“x”,它就不会删除任何内容
标签: python-3.x pandas dataframe duplicates partial-matches