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
#1
Good evening,

can someone help me with the syntax in saving the rows of a csv files with M rows and N columns into a list?
I do not want the last column, but all of the M rows.
Thus, the list should look like an M x (N-1) matrix.
The last column should be saved to a Y list.

In my case, N=82 and M=26000.

import csv
import os

#give path to training / test data files
data_path='XXX'

#READ IN DATA 
x_training = []
y_training = []
print(os.getcwd())
with open(data_path) as csv_file:
    data = csv.reader(csv_file, delimiter=",")
    for row in data:
        for k in range(81):
            # now what? How do I write it :(
        y_training.append(float(row[-1]))
Regards!
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