Read in the first column of a CSV in python
<p>I have a CSV (mylist.csv) with 2 columns that look similar to this:</p>

<blockquote>
<pre><code>jfj840398jgg     item-2f
hd883hb2kjsd     item-9k
jie9hgtrbu43     item-12
fjoi439jgnso     item-3i
</code></pre>
</blockquote>

<p>I need to read the first column into a variable so I just get:</p>

<blockquote>
<pre><code>jfj840398jgg
hd883hb2kjsd
jie9hgtrbu43
fjoi439jgnso
</code></pre>
</blockquote>

<p>I tried the following, but it is only giving me the first letter of each column:</p>

<pre><code>import csv
list2 = []
with open("mylist.csv") as f:
    for row in f:
        list2.append(row[0])
</code></pre>

<p>so the results of the above code are giving me list2 as:</p>

<blockquote>
  <p>['j', 'h', 'j', 'f']</p>
</blockquote>

<p>you import <code>csv</code>, but then never use it to actually read the CSV.  Then you open <code>mylist.csv</code> as a normal file, so when you declare:</p>

<pre><code> for row in f:
    list2.append(row[0])
</code></pre>

<p>What you're actually telling Python to do is "iterate through the lines, and append the first element of the lines (which would be the first letter) to <code>list2</code>".  What you need to do, if you want to use the CSV module, is:</p>

<pre><code>import csv
with open('mylist.csv', 'r') as f:
    csv_reader = csv.reader(f, delimiter='     ')
    for row in csv_reader:
        list2.append(row[0])
</code></pre>

python csv