Currently, I am attempting to retrieve numeric data from different CSV files. I then place that data in lists in Python. However, I’m struggling to get Python to determine if there is a value in each separate list of data that is greater than a certain number. I need to be able to search each list separately for some value at which point Python should return some text of my choice. I’m not sure what I’m missing, but Python doesn’t seem to be handling my syntax as I was hoping.
import csv
stocks = ['JPM','PG','KO','GOOG']
for stock in stocks:
Data = open("%sMin.csv" % (stock), 'r')
Ticker = []
for row in Data:
Ticker.append(row.strip().split(','))
if Ticker > 735:
print "%s Minimum" % (stock)
I modified the code the other stock became Ticker to remove the confusion.
There are three things wrong, preventing you from getting the result.
stockis a list of values, so you aren’t able to directly do a numeric comparison to the list itself.First, append floats to your list:
Second, figure out which index of your split row is the numeric value. If they are all numeric values, then add them all to the list by extending:
If its say, the first column, add just that one:
Third, if you simply want to know if a value greater than 735 is in your list, you can simply ask it for the max value of the list: