Nov-20-2018, 01:51 PM
First, clarify the row one. I expect that means the first data point. But if the csv file has headers, that's going to be on the second row (row[1] with 0-indexing).
I would not trust isnumeric unless you have been told it's okay to do so for this exercise. '-1' and '3.5' give False for isnumeric. Do you need to distinguish between ints and floats? If not you can just use float() with a try/except block, otherwise you'll have to test both. Has your teacher covered try/except blocks yet?
When you get to the right row to check, you need to have a subloop to loop though the fields in the row (
To get unique values use set(). Start with a list of one set for every column. Then have another subloop just like the one above to add each item to the correct set:
I would not trust isnumeric unless you have been told it's okay to do so for this exercise. '-1' and '3.5' give False for isnumeric. Do you need to distinguish between ints and floats? If not you can just use float() with a try/except block, otherwise you'll have to test both. Has your teacher covered try/except blocks yet?
When you get to the right row to check, you need to have a subloop to loop though the fields in the row (
for field in row:
). Then check each field for numeric or string.To get unique values use set(). Start with a list of one set for every column. Then have another subloop just like the one above to add each item to the correct set:
for column, item in enumerate(row): unique[column].add(item)After reading the whole file, the len of each set will be the number of items in that column.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures