A row in a csv reader object is a list of strings. You need to check each item in the list individually. For example, to check if the first two items in the row are numeric you can do:
if all(col.isnumeric() for col in (row[0], row[1])):
Note that there is no need to check equality with True.
Some clarification can be helpful. What values do you want to append? First and second character or word? Do you want to look for digit in whole row or only in first two words/characters? What you consider numeric?
I am sharing some portion of csv file…please check the image.
2 things, i want to stop appending if number hit 700…or if the code detect none numeric values. In the image are → “”“”.
First col is X and the 2nd col is Y…thanks in advance
X Y
2 1.15E-10
4 1.15E-09
8 1.15E-11
9 1.15E-12
. .
. .
700 1.15E-13
Your file contains some numbers with scientific notation (1.15E-10, for example). This will be a problem; str.isnumeric() will not correctly identify these as floats. I suggest using a more sophisticated tool to read the file, like pandas.
You could also do it by calling float on them directly inside a try/except:
This numeric value must be in first column (before first comma)? Or first and second?Does row A,B,C,4 contains numeric value or not? Do you want append int or str?
You are using str.isnumeric, does that mean this is accepted behaviour:
>>> nums = ['123', '一二三', '1²'] # second item is 123 in Kanji
>>> for num in nums:
... print(num.isnumeric())
...
True
True
True