0
import csv
with open('doc.csv','r') as f:
                file=csv.reader(f)
                for row in file:
                      if row==['NAME']:
                               print(row)

I wanted to print all the names from a csv file in python. I tried this using this method but I got a blank output. Can anyone help me out ?

1 Answers1

1

row is just a list, if you want first column from row, try:

print(row[0])

if you want all row, just

print(row[:])

if you want cells number 2 and 4:

print(row[1],row[3])

if you really want to have a better control of csv try with read_csv() pandas method:

import pandas as pd

df = pd.read_csv('AAPL.csv')
print(df['your_field_name_here'])