The problem statement is incomplete, so we cannot conclude.
Is it a list of strings ? integers ? floats ? with None ? with float("NaN") ? a mix of all ?
With a list of mixed numbers and strings, you would have:
life_expectancy= [2,3,5,7,11,13, "", 0, "", 3.14, 1.414, "", 1.712, "", 1.618, 0]
index1 = (life_expectancy.index(min(life_expectancy,)))
TypeError: '<' not supported between instances of 'str' and 'int'
index1 = (life_expectancy.index(min(life_expectancy,key=int)))
ValueError: invalid literal for int() with base 10: ''
With a list of mixed numbers, None, and strings, you would have:
life_expectancy= [2,3,5,7,11,13, None, 0, None, 3.14, 1.414, None, 1.712, None, 1.618, 0]
index1 = (life_expectancy.index(min(life_expectancy,)))
TypeError: '<' not supported between instances of 'NoneType' and 'int'
index1 = (life_expectancy.index(min(life_expectancy,key=int)))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
So, yeah ... it all depends on your actual inputs...
Stef's answer should do the trick.
otherwise:
life_expectancy= [2,3,5,7,11,13, "", "0", "", "3.14", 1.414, "", 1.712, "", 1.618, 0]
new_list = [e for e in life_expectancy if e and type(e) != str]
new_list
>>> [2, 3, 5, 7, 11, 13, 1.414, 1.712, 1.618]
you may consider using pandas and its read_csv() function, quopting:
Read a comma-separated values (csv) file into DataFrame.
Also supports optionally iterating or breaking of the file into chunks.
Give a special look to all the doc/parameters, because there are a lot of default values and inferences, especially:
sepstr, default ‘,’
Delimiter to use.
and:
decimalstr, default ‘.’
Character to recognize as decimal point (e.g. use ‘,’ for European data).
(and a lot more)