Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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?

like image 376
Emma Lim Avatar asked Jan 26 '26 03:01

Emma Lim


1 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

like image 127
Abhi Avatar answered Jan 27 '26 16:01

Abhi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!