I have a .csv file with a lot of data in it. I tried to open it with:
import csv
filename = raw_input('Your filename: ')
with open(filename,'r') as myFile:
dataFromFile = csv.reader(myFile)
print dataFromFile
As far as I know csv.reader
converts the data from the file into a list.
I wanted to open the file
2015-09-02_17:59:43.csv
But I get the following error:
IOError: [Errno 2] No such file or directory: '2015-09-02_17:59:43.csv '
Ok, I googled it and found the following question on stack overflow: Trying to use open( filename, 'w' ) gives IOError: [Errno 2] No such file or directory: So I tried the solution from there. But then I got another error:
OSError: [Errno 2] No such file or directory: ''
Then I renamed my file to timestamp.csv because I was curious if the name might be an issus and tried my first solution.
So suddenly the file could be found but as a print output I got the following:
<_csv.reader object at 0x104c88a60>
. I thought if I printed dataFromFile
out it would show me the entire list.
So first question here: Does this <_csv.reader object at 0x104c88a60>
mean that the list is to long to be displayed so it just tells me what object I have ?
Second question: Why didn't my previous attempts to solve work?
And I found a little workaround with:
for currentRow in dataFromFile:
print currentRow
So row after row is printed out. But not exactly what I wanted.
Last but not least I want to transform my list into a numpy array what would be the easiest way ?
EDIT I already found an answer and way for my last question, it is pretty easy I guess:
import numpy as np
np.array(dataFromFile)