python - 如何通过在 python 中读取 csv 来检查特定列中值的大小

标签 python

enter image description here

当我调用一个csv文件时,我想比较特定列中的值是否大于特定值。然后,我想放一个弹出窗口。

import ctypes
import csv

        reader = csv.reader(csv_file_name)

        for row in reader:
            if(row[3]>=5):
                mymessage = 'A message'
                title = 'Popup window'
                ctypes.windll.user32.MessageBoxA(0, mymessage, title, 0)
            else:
                continue

为了解决这个问题,我写了上面的代码,没有任何反应。在这里,我想检查列中的值是否均大于“5”并显示一个弹出窗口。代码的哪一部分是错误的?

最佳答案

我获取了包含以下数据的 csv:

enter image description here

代码有效:添加 int(row[3])>=5

import ctypes
import csv

with open('data.csv') as csv_file:
    reader = csv.reader(csv_file)
    for row in reader:
        if(int(row[3])>=5):
            mymessage = 'A message'
            title = 'Popup window'
            ctypes.windll.user32.MessageBoxA(0, mymessage, title, 0)
        else:
            continue

结果:
enter image description here

关于python - 如何通过在 python 中读取 csv 来检查特定列中值的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68342797/

相关文章:

Python 3.8 结构体解包 - struct.error : unpack requires a buffer of 1 bytes

python - SQLAlchemy:使用声明式更新的更好方法?

python - uWSGI 是否在启动时启动所有进程?

python - 如何为numpy数组创建圆形蒙版?

python - 使用lepture/authlib获取refresh_token

python - 如何创建 Python 鸡蛋文件

python - celery 使用错误的 python 版本

python - 使用替换字典替换字符串的最简单方法?

Python setuptools 无法找到库的子模块

python-dev安装报错: ImportError: No module named apt_pkg