Python Forum
reading in csv row by row
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading in csv row by row
#8
woooee has posted code what to do with rows in order to get needed data (slicing and appending).


PS - if you overstated your knowledge ("I have learned to use the .csv reader and I will stick to it for now") then you should refresh your memory by reading documentation csv.reader

Depending on your needs (do you want skip first row or not) you can iterate over reader object directly as (per documentation): "Return a reader object which will iterate over lines in the given csvfile. csvfile can be any object which supports the iterator protocol and returns a string each time its __next__() method is called — file objects and list objects are both suitable."

You can iterate over reader object directly:

>>> x_training = list()
>>> y_training = list()
>>> with open(csv_file, "r") as data:
...     for row in csv.reader(data, delimiter=','):
...         x_training.append(row[:-1])
...         y_training.append(row[-1])
...
I also suggest reading DeaD_EyE post carefully. Without fundamentals it's hard to write code which delivers results you want.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
reading in csv row by row - by SchroedingersLion - Jan-08-2019, 07:01 PM
RE: reading in csv row by row - by woooee - Jan-08-2019, 07:18 PM
RE: reading in csv row by row - by woooee - Jan-08-2019, 07:55 PM
RE: reading in csv row by row - by DeaD_EyE - Jan-08-2019, 10:17 PM
RE: reading in csv row by row - by Gribouillis - Jan-09-2019, 07:28 AM
RE: reading in csv row by row - by perfringo - Jan-09-2019, 07:42 AM
RE: reading in csv row by row - by woooee - Jan-09-2019, 06:26 PM
RE: reading in csv row by row - by perfringo - Jan-10-2019, 12:49 PM

Forum Jump:

User Panel Messages

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