How to read columns from CSV file in Python
<pre><code>def rowfilter():
    field_data = {}
    try:
        csv_read = csv.reader(open('sample.csv', ), delimiter=',', quotechar='|')
        for row in csv_read:
            for field in row[7]:
                print(field)       


    except FileNotFoundError:
            print("File not found")

rowfilter()
</code></pre>

<p>This code runs successfully but I want this code to print data prior to the user_input.
e.g. if user enter 5 then its should print all the details from 1 to 5, along with all the column associated with it.</p>

<p>This is almost certainly a job for <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">pandas</a></p>

<pre><code>import pandas as pd

df = pd.read_csv('sample.csv', delimiter=',', quotechar='|')

#you can get the 7th column like this
df_seven = df[df.columns[7]]

#Then slice the dataframe as you see fit
df_seven[0:5] # first five rows
df_seven[4:9] # rows 4 to 9... etc
</code></pre>

python python-3.x csv