1

Having an issue with reading a csv file that delimits everything with commas, but the first one in the csv file does not contain quotes. Example:

Symbol,"Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary Quote", 

the code used to try and read this is as follows:

from ystockquote import * import csv with open('companylist.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL) for row in readCSV: print(row[0]) 

What I get is the following:

Symbol,"Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary Quote",; 

However, I just want to get all of the symbols from this list. Anyone an idea on how to do this?

edit

More data:

Symbol,"Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary Quote",;

PIH,"1347 Property Insurance Holdings, Inc.","7.505","$45.23M","2014","Finance","Property-Casualty Insurers","http://www.nasdaq.com/symbol/pih",;

FLWS,"1-800 FLOWERS.COM, Inc.","9.59","$623.46M","1999","Consumer Services","Other Specialty Stores","http://www.nasdaq.com/symbol/flws",;

So my expected output would be:

Symbol PIH FLWS 

This would happen if the csv.reader read my file as each of the rows as a seperate list, and within each of these lists all of the items (delimited by commas) would be their seperate values. (e.g. symbol would be the value of [0], "name" would be the value of [1], etc.)

I hope this clears up what I'm looking for

1
  • Can you show your expected output Commented Oct 26, 2016 at 14:29

2 Answers 2

2

Found the easy way out:

Replaced all of the

" 

with nothing in my csv file, this made it so that the csv.reader could read the csv file normally again.

Sign up to request clarification or add additional context in comments.

Comments

0

If print(row[0]) is giving you a list, it might be because each row of your csv file is being read in as a list.

try print(row[0][0]) maybe?

1 Comment

This doesn't work unfortunately, it would give me only the letter "S" as a string from, of course, Symbol.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.