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日
  • 展开全部

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计