title: Accessing column data from a CSV file in Python
body: <p>I have a CSV file with A, B, C, D columns and N rows. 
  The problems is that the data in these columns is not of the same length i.e some are 4.5 and some are 4.52. </p>
  
  <p>My question is in two parts : </p>
  
  <p>How do i access these columns from the csv files. 
  I've used this code to print the contents of the csv file and to read them into an array</p>
  
  <pre><code>    import csv
      with open('file.csv','rb') as f:
          reader = csv.reader(f)
          for row in reader:
              print row
  </code></pre>
  
  <p>to print the rows in the CSV file and i replaced </p>
  
  <pre><code>    print row 
  </code></pre>
  
  <p>with </p>
  
  <pre><code>    z = row
      z.append(z)
  </code></pre>
  
  <p>to save the data into an array. </p>
  
  <p>But z is a 1-D array. And the data is of type string. When i try performing operations of the type np.median(z), it gives me an error. Also, i cannot do </p>
  
  <pre><code>    z.append(float(z))
  </code></pre>
  
  <p>This is giving me a TypeError. </p>
  
  <p>And, is there anyway to truncate the values and set them to a certain precision while we are importing them from the csv file?! Like, if the file has values like 4.3, 4.56, 4.299, ..., i want to constrain what i finally import to just one decimal point.</p>
  
  <p>This SE question is the closest to answering my 2nd question - <a href="https://stackoverflow.com/questions/2549746/python-csv-large-file-with-rows-of-different-lengths">Python - CSV: Large file with rows of different lengths</a> - but i do not understand it. If any of you can help me regarding this, I'd be thankful. </p>
  
  <p>EDIT 1 : 
  @ Richie : here's a sample data set - <a href="http://goo.gl/io8Az" rel="nofollow noreferrer">http://goo.gl/io8Az</a>. It links to a google doc. 
  And regd your comment, this was the outcome with i ran your code on my csv file - </p>
  
  <pre><code>     ValueError: could not convert string to float: plate
  </code></pre>
  
  <p>@ Pieters : z = row, z.append(z) created this - 
  ['3836', '55302', '402', '22.945717', '22.771544', '23.081865', '22.428421', '21.78294', '164.40663689', '-1.25641627', '1.780485', '1237674648848106129', [...]]. </p>
  
  <p>I should've mentioned that i've just started using python and i'm learning things on a need-to-know basis! I'm improvising with bits and pieces of code i'm finding on the web. </p>
  
  <p>EDIT 2: 
  I've heard about pandas. I guess i should start using it.</p>
  
  <p>@ Khalid - i've run your code and i'm able to retrieve the column i want. 
  Instead of printing the whole row out, can i access it instead?! as a static array?! </p>
  
  <p>EDIT 3: 
  @ richie : the first time i ran your code, this showed up - </p>
  
  <p>Traceback (most recent call last):
    File "", line 4, in 
  ValueError: could not convert string to float: plate</p>
  
  <p>well, i realized that the first row containing the column names is the cause, so i removed the first row, saved this as a new file and ran the code on that file and it worked perfectly fine. </p>
  
  <p>But, if i do remove the first line, which contains the column identifiers, i cannot use the method mentioned by khalid below. I am looking at pandas in the meanwhile. </p>
  
  <p>Thanks for everything guys :)</p>
  
  <p>EDIT 4 : 
  Lesson Learnt. Pandas is Awesome. Job Done :)...</p>