Q:

Could not convert string to float in generator

I am trying to do some basic operations with a nest listed of data in Python 2.7.  A simplified version of my data is presented below:
resultlistdata = [
['sell','EURUSD',-1092.0,'Sometext'],
['buy','GBPUSD',2342.0,'Moretext'],
['buy','EURUSD',2122.0,'Yetmoretext'],
['not opened','','',''],
['sell','EURJPY',-483,'Difftext'],
['sell','EURJPY',269,'Anothertext'],
etc...
]

The list is a few thousand lines long.  I'm trying to count the number of times the third item in the list is greater than or equal to zero (so the correct result in the case above would be 3).  I am using the generator expression (or is it list comprehension?):
profittrades = sum(1 for x in resultdatalist if x[2] >= 0)

which gives an answer equal to the number of items in the list (so 6 in the case above, which is wrong).  I have also tried:
profittrades = sum(1 for x in resultdatalist if float(x[2]) >= 0)

which gives the error "ValueError:  Could not convert string to float".
I am almost certain the problem is caused by the line where the 'not opened' occurs, and it cannot convert the empty string to a float, I just don't know what to do about it!
Is there a way to do the counting using a 'one-liner' list comprehension approach, or do I need to make a loop?  
The "resultslistdata" is compiled by me, so if there is something clever I can do when creating it that would help I can give it a try.  Im reluctant to enter a value of "0" as the profit for trades that are "never opened" because later when I do averages it will skew my results (?!).
Thank you to anyone who can help me!

A:

If all trades that were never opened (or something of that sort) are all blanks '', then you can do:
profittrades = sum(1 for x in resultdatalist if x[2] and float(x[2]) >= 0)

This checks first that the string is not falsy i.e. blank, before attempting the float cast.

