You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何筛选DataFrame邮箱:保留企业域名邮箱,删除个人邮箱

解决方案

你可以通过 Pandas 的字符串处理方法结合布尔索引来实现邮箱过滤,以下是两种实用方案:

方法1:批量匹配后缀过滤

先定义需要排除的个人邮箱后缀,再通过取反操作保留企业邮箱:

# 列出要剔除的个人邮箱后缀
exclude_suffixes = ('gmail.com', 'hotmail.com', 'yahoo.com')

# 过滤DataFrame,保留不在排除列表中的邮箱
filtered_df = dffinal[~dffinal['email'].str.endswith(exclude_suffixes)]

方法2:正则表达式精确匹配

如果需要避免误判带多级域名的特殊情况(比如xxx@gmail.com.cn),可以用正则精准匹配邮箱结尾:

# 正则规则:匹配以指定后缀结尾的邮箱,$表示字符串结束
pattern = r'@(gmail|hotmail)\.com$|@yahoo\.com$'

# 过滤掉符合正则规则的个人邮箱
filtered_df = dffinal[~dffinal['email'].str.contains(pattern, regex=True)]

运行后,filtered_df 将只保留企业域名邮箱,对应你提供的数据,结果为:

  • corporate@rocketbank.com.br
  • corporate@santander.com.br
  • corporate@revelo.fr
  • corporate@valemobi.com.br

内容的提问来源于stack exchange,提问作者Daniel Rondon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 14:40:50