Assuming that this is your actual code, the problem is that you never open the file. Your csv_file_object
is still just the fileName
, and thus your data
is made up of the characters of that file name, resulting in a 1D numpy array.
Instead, you should open
the file and create a csv.reader
for it.
import csv
with open(fileName) as f:
reader = csv.reader(f)
data=[]
for row in reader:
data.append(row)
data = np.array(data)
Or shorter: data = np.array([row for row in csv.reader(f)])
Update: The new error you are getting is probably due to you accidentally changing
os.path.join('train.csv')
to os.path('train.csv')
, i.e., instead of calling the join
function from the os.path
module, you are (trying to) call the module itself.
Update: It seems your train.csv
file is not in the same directory as your Python script, thus the script won't find the file if you just use the filename. You have to use the absolute path together with the filename:
fileName = os.path.join('/Users/scdavis6/Desktop', 'train.csv')
Or just fileName = '/Users/scdavis6/Desktop/train.csv'
. Alternatively, move your train.csv
file to the same directory as your Python script. This might indeed be the better and more robust option, unless you are using this file in multiple scripts in different directories.