This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bs4 as bs | |
import pickle | |
import requests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html = requests.get('http://en.wikipedia.org/wiki/List_of_S%26P_500_companies') | |
soup = bs.BeautifulSoup(html.text, 'lxml') | |
table = soup.find('table', {'class': 'wikitable sortable'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tickers = [] | |
for row in table.findAll('tr')[1:]: | |
ticker = row.findAll('td')[0].text | |
ticker = ticker[:-1] | |
tickers.append(ticker) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("sp500tickers.pickle", "wb") as f: | |
pickle.dump(tickers, f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime as dt | |
import os | |
import pandas_datareader.data as pdr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("sp500tickers.pickle", "rb") as f: | |
tickers = pickle.load(f) | |
if not os.path.exists('stock_dfs'): | |
os.makedirs('stock_dfs') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start = dt.datetime(20XX, 1, 1) | |
end = dt.datetime.now() | |
for ticker in tickers: | |
if not os.path.exists('stock_dfs/{}.csv'.format(ticker)): | |
df = pdr.DataReader(ticker.replace('.', '-'), 'yahoo', start, end) | |
df.reset_index(inplace=True) | |
df.set_index("Date", inplace=True) | |
df.to_csv('stock_dfs/{}.csv'.format(ticker)) | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let sumLargestNumbers = function(data) { | |
let sorted = data.sort(function(a,b){ | |
return b - a; | |
}) | |
return sorted[0] + sorted[1]; | |
}; | |
console.log(sumLargestNumbers([1, 10])); | |
console.log(sumLargestNumbers([1, 2, 3])); | |
console.log(sumLargestNumbers([10, 4, 34, 6, 92, 2])); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let conditionalSum = function(values, condition) { | |
var sum = 0; | |
values.forEach( function(value) { | |
if(condition == "even" && value % 2 === 0) { | |
sum += value; | |
} else if (condition == 'odd' && value % 2 !== 0) { | |
sum +=value; | |
} | |
}); | |
return sum; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numberOfVowels = function(data) { | |
let count = 0; | |
for (var i = 0; i < data.length; i++) { | |
if(data[i] === 'a' || data[i] === 'e' || data[i] === 'i' || data[i] === 'o' || data[i] === 'u') { | |
count++; | |
} | |
} | |
return count; | |
}; |
OlderNewer