Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's worth noting that you should try to use <a href="http://preshing.com/20110920/the-python-with-statement-by-example" rel="nofollow">the <code>with</code> statement</a> when opening files in Python. This is both more readable and removes the possibility of a file being left unclosed (even when exceptions occur).</p> <p>Your actual problem comes in that you are not doing what you want to do. </p> <pre><code>reader = csv.reader(filein, skipinitialspace = True) listofxys = [] for row in reader: listofxys.append(row) </code></pre> <p>All this does is <code>reader = list(csv.reader(filein, skipinitialspace = True))</code> in a very inefficient manner.</p> <p>What you want to do is use <a href="http://docs.python.org/library/functions.html#zip" rel="nofollow">the <code>zip()</code> builtin</a> to take a list of pairs and turn it into two lists. You do this with the star operator:</p> <pre><code>import csv with open("test") as filein: reader = csv.reader(filein, skipinitialspace = True) xs, ys = zip(*reader) print(xs) print(ys) </code></pre> <p>Which gives:</p> <pre><code>('10', '2', '5', '7', '9', '3', '2', '6', '0', '5') ('5', '4', '6', '8', '12', '45', '4', '5', '3', '6') </code></pre> <p>Do note the fact these values are strings. If you want to have them as numbers, you will want to use <a href="http://docs.python.org/library/csv.html#csv.QUOTE_NONNUMERIC" rel="nofollow"><code>csv.QUOTE_NONNUMERIC</code></a>, e.g: <code>reader = csv.reader(filein, quoting=csv.QUOTE_NONNUMERIC, skipinitialspace = True)</code></p> <p>Which gives:</p> <pre><code>(10.0, 2.0, 5.0, 7.0, 9.0, 3.0, 2.0, 6.0, 0.0, 5.0) (5.0, 4.0, 6.0, 8.0, 12.0, 45.0, 4.0, 5.0, 3.0, 6.0) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload