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

如何使用Python筛选数据列中以+61开头的电话号码

筛选+61开头电话号码的Python实现方案

场景1:使用Pandas处理表格数据(CSV/Excel场景通用)

这是数据处理中最常用的场景,直接调用字符串匹配方法即可:

import pandas as pd

# 示例数据,可替换为pd.read_csv()/pd.read_excel()读取你的本地文件
df = pd.DataFrame({
    "id": [1,2,3,4,5],
    "phone": ["+61412345678", "0412345678", "+61498765432", "+8613800000000", "+61398765432"]
})

# 核心筛选逻辑,na=False用于自动跳过空值避免报错
filtered_df = df[df["phone"].str.startswith("+61", na=False)]

场景2:纯Python处理电话号码列表

如果你的数据存储在Python原生列表中,用列表推导式即可完成筛选:

phone_list = ["+61412345678", "0412345678", "+61498765432", "+8613800000000", "+61398765432"]
filtered_phones = [phone for phone in phone_list if phone.startswith("+61")]

常见问题处理

  • 如果电话号码列是数值类型,先转字符串再筛选:df["phone"] = df["phone"].astype(str)
  • 如果号码首尾存在空格,先做去空格处理再匹配:df["phone"].str.strip().startswith("+61", na=False)

内容的提问来源于stack exchange,提问作者Simon Soltanian

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 02:24:01