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

如何将tolist结果拆分为数字开头和名称两类新列表?

拆分发货单号检查结果为数字开头条目与名称类条目

现有一段用于检查发货单号是否存在于销售报告中的代码:

dfn = dfn.astype('str')
diff = dfn[~dfn['Numero de Envio'].isin(dfn['Unnamed: 13'])].dropna()[['Numero de Envio','Fecha']].values.tolist() 
print(f"\n Hay ventas que podrían no ser nuestras: \U0001F611 - Revisar :" '\n')
diff 

运行后得到以下结果:

[['piedras blancas', '2022-12-01'],
 ['41845010982', '2022-12-01'],
 ['carrasco norte', '2022-12-05'],
 ['41855309788', '2022-12-05'],
 ['villa española ', '2022-12-07'],
 ['aires puros', '2022-12-08'],
 ['monica villa borges', '2022-12-08'],
 ['nicolas diego ', '2022-12-08'],
 ['enrique permuy', '2022-12-08'],
 ['natalia blanco', '2022-12-08'],
 ['laurita', '2022-12-09'],
 ['hugo carrion', '2022-12-10'],
 ['4187289809', '2022-12-12'],
 ['mariana', '2022-12-12'],
 ['amelia vignolo', '2022-12-14'],
 ['leonardo saucedo', '2022-12-14'],
 ['14891993727', '2022-12-17'],
 ['maria noel dottone', '2022-12-19'],
 ['41899599250', '2022-12-19'],
 ['41898783286', '2022-12-19'],
 ['corpo pilates ltd', '2022-12-19'],
 ['serrana bentancour', '2022-12-20'],
 ['fabiana lima', '2022-12-21'],
 ['41916589225', '2022-12-26'],
 ['41917845465', '2022-12-26'],
 ['41916895866', '2022-12-26'],
 ['41917386564', '2022-12-26'],
 ['41917285884', '2022-12-26'],
 ['41900719115', '2022-12-27'],
 ['mauro gonzalez', '2022-12-27']]

需要将上述结果拆分为两组:一组是首字符为数字的条目,另一组是名称类条目。

解决方案

通过遍历结果列表,判断每个条目的第一个元素首字符是否为数字,将其分别存入两个列表即可:

# 初始化两个空列表用于分类存储
numeric_entries = []
name_entries = []

# 遍历结果列表进行分类
for item in diff:
    # 检查第一个元素的首字符是否为数字
    if item[0][0].isdigit():
        numeric_entries.append(item)
    else:
        name_entries.append(item)

# 输出数字开头的条目
print("数字开头的发货单号条目:")
for entry in numeric_entries:
    print(entry)

# 输出名称类条目
print("\n名称类条目:")
for entry in name_entries:
    print(entry)

运行后即可得到符合需求的两组分类结果。

内容的提问来源于stack exchange,提问作者Franco Vera

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 17:45:29