title: uploading mixed data from csv into a numpy array in python
body: <p>I have a csv file that contains 10 columns and 6 rows that I want to convert into a numpy array. Although it loads, I cannot use the data right now and I think I am missing a step.</p>
  
  <p>My code right now looks like this </p>
  
  <pre><code>import numpy as np
  
  filename = "test_ioc.csv"
  
  # open file
  f=open(filename)
  
  # initialize this 
  myfile = [] 
  
  # Convert to numpy array
  mat = np.vstack([signal for signal in f.readlines()])
  print mat
  </code></pre>
  
  <p>alternatively, I have also done this:</p>
  
  <pre><code>import numpy as np
  
  filename = "test_ioc.csv"
  
  # open file
  f=open(filename)
  
  # initialize this 
  myfile = [] # empty nested list that is the big container, this contains all the rows
  
  # f.readlines, and for each line,
  for line in f.readlines():
  
  #create a list for each row
  row = [] # empty list for row items, each row has 2 lists
  
  # line.strip, line.split, and for each i in this:
  for eye in line.strip().split():
  
      # convert elements into floats
  
      row.append(eye) # append each item to list 'row'
  
  
  # append all the parts row to the list myfile that you created
  myfile.append(row) #append list to my file
  
  print myfile
  
  # now that you have your gigantic list myfile, convert to it to numpy array
  a = np.array(myfile) #convert the list into a numpy array
  
  # slice accordingly!
  x = a[:,0] #first column
  y = a[:,1] #second column
  f.close() 
  </code></pre>
  
  <p>The first one gives me an output like this:</p>
  
  <pre><code>print a
      [['2043l0.wav,0.115,0.169,0.222,0.23,2043l0.wav,0.21,0.169,0.238,0.23']
   [ 'dn2001l0.wav,0.105,0.161,0.242,0.222,dn2001l0.wav,0.153,0.176,0.207,0.207']
   ['2694l0.wav,0.13,0.192,0.33,0.314,2694l0.wav,0.192,0.184,0.207,0.238']
   ['2641l0.wav,0.123,0.146,0,0.407,2641l0.wav,0.199,0.199,0.199,0.176']
   ['2622l0.wav,0.284,0.353,0.582,0.582,2622l0.wav,0.268,0.161,0.176,0.184']
   ['dn2047l0.wav,0.12,0.23,0.368,0.322,dn2047l0.wav,0.369,0.169,0.207,0.222']]
  </code></pre>
  
  <p>I really need to split my rows further into 2 sets of 4, convert each number in each row into a float but I am new to python and just want to be able to do some basic operations on my data and graph it using matplotlib. Thanks for your help!</p>