# List of Stocks by Sector

Does anyone know where I can find a list of all stocks traded on the NYSE in a table that also includes what sector they are in? I want to look at some data using info both from the individual stock and from the sector but I cannot find a comprehensive list containing both pieces of information.

I just ran the Mathematica code below to make a list of stocks and sectors you can access here:

https://www.dropbox.com/s/zkzpcnksvfygamp/nyse.xls

Mathematica uses curated data from Yahoo. Items that lack sector information have been omitted. The list may be incomplete but it might provide something for you to work with.

members = FinancialData["NYSE", "Members"];
names = If[SameQ[Head[#], FinancialData], "-", #] &@
FinancialData[#, "Name"] & /@ members;
companies = If[SameQ[Head[#], FinancialData], "-", #] &@
FinancialData[#, "Company"] & /@ members;
sectors = If[SameQ[Head[#], FinancialData], "-", #] &@
FinancialData[#, "Sector"] & /@ members;
data = Transpose[{members, names, companies, sectors}];
data2 = DeleteCases[data, {_, _, _, Missing["NotAvailable"] | "-"}];
data3 = SortBy[data2, Last];
Export["nyse.xls",
Prepend[data3, {"Symbol", "Name", "Company", "Sector"}]];


Your best bet is to use the stock screener over at FINVIZ. You can limit the results to NYSE listed stocks and can easily export to CSV using the "export" link at the bottom right of the table.

Bear in mind, industry/sector classifications are no uniform. You'll find different classification methods depending on where you look.

As @Louis said, from Finviz's stock screener you can filter by exchange and sort column by sector.

>>> import urllib2
>>> url = "http://www.finviz.com/export.ashx?v=111&f=exch_nyse&o=sector"
>>> file = open("tickers.txt",'wb')