m0_62909636 2021-12-23 11:56 采纳率: 95.5%
浏览 63
已结题

python 如何过滤排除非数字的列表

问题遇到的现象和发生背景

我在做导入excel表的数据处理,表中一些不带数字的行和带有“无服务”见下“字的行我不想要。用elif没有过滤掉,想问下问题出在哪,有没有更好的方法过滤?

img

# data.rows 为表格内的每一行数据  
for index, row in enumerate(data.rows):# 循环获取表格内的每一行数据
    if index < 9: # 判断index为该行跳出本次循环忽略本次数据 就不会再添加了
        continue
    elif index == 26: 
        continue
    elif index == 33: 
        continue
    elif index == 34: 
        continue
    elif index == 65: 
        continue
    elif index == 66: 
        continue
    elif index == 102: 
        continue
    elif index == 125: 
        continue
    elif index == 163: 
        continue
    elif index == 188: 
        continue
    elif index > 192:
        continue    

img

  • 写回答

1条回答 默认 最新

  • chuifengde 2021-12-23 13:32
    关注
    
    for row in data.rows:
        if row[0].value in [17, 24, 25]:
            continue
        else:
            你的处理
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月31日
  • 已采纳回答 12月23日
  • 修改了问题 12月23日
  • 修改了问题 12月23日
  • 展开全部

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面