How to check the size of values in a particular column by reading csv in python

Viewed 202

enter image description here

When I call a csv file, I want to compare whether the values in a particular column are greater than a particular value. Then, I'd like to put on a pop-up window.

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

To solve this problem, I wrote the code above and there was no response. Here, I want to check if the values in the column are each greater than "5" and show a pop-up window. What part of the code is wrong?

2 Answers

I took a csv with following data:

enter image description here

code worked: on adding 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

result:
enter image description here

import ctypes
import csv

reader = csv.reader(csv_file_name)

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

Try using this code. You don't need to compare the entire column, but only the cells inside this column

Related