Python function to create an array of particular column of csv file
<p>I need to write a function that, given a CSV file name as a string and a column number, will create an array with the distinct values in that particular column of the file. Assuming my first column is 0 just like in Python lists. This file also has a header and footer row.</p>

<pre><code>import csv

def facet(file, column):
    """ (str, int) -&gt; array
Gets a list of distinct values from the specified column in the input file.
"""
</code></pre>

<p>Try the following:</p>

<pre><code>import csv

def facet(file, column):
    with open(file, newline='') as f_input:
        return [row[column] for row in csv.reader(f_input)][1:-1]

print(facet('input.csv', 1))
</code></pre>

<p>The reads the file as a <code>csv</code> and uses a list comprehension to select only only cell from each row and build a list. Finally <code>[1:-1</code> is used to skip over header and footer in your file.</p>

python arrays python-3.x csv