Python Forum
Hi how to take row 1 for every column and check the value what class is it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hi how to take row 1 for every column and check the value what class is it
#2
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 (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
Reply


Messages In This Thread
RE: Hi how to take row 1 for every column and check the value what class is it - by ichabod801 - Nov-20-2018, 01:51 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020