Skip to content

Instantly share code, notes, and snippets.

@shashankvemuri
Created August 16, 2020 20:58
Show Gist options
  • Save shashankvemuri/828c37c3693e607c35fffd3a0592eaaf to your computer and use it in GitHub Desktop.
Save shashankvemuri/828c37c3693e607c35fffd3a0592eaaf to your computer and use it in GitHub Desktop.
functions
def get_fundamentals():
try:
# Find fundamentals table
fundamentals = pd.read_html(str(html), attrs = {'class': 'snapshot-table2'})[0]
# Clean up fundamentals dataframe
fundamentals.columns = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11']
colOne = []
colLength = len(fundamentals)
for k in np.arange(0, colLength, 2):
colOne.append(fundamentals[f'{k}'])
attrs = pd.concat(colOne, ignore_index=True)
colTwo = []
colLength = len(fundamentals)
for k in np.arange(1, colLength, 2):
colTwo.append(fundamentals[f'{k}'])
vals = pd.concat(colTwo, ignore_index=True)
fundamentals = pd.DataFrame()
fundamentals['Attributes'] = attrs
fundamentals['Values'] = vals
fundamentals = fundamentals.set_index('Attributes')
return fundamentals
except Exception as e:
return e
def get_news():
try:
# Find news table
news = pd.read_html(str(html), attrs = {'class': 'fullview-news-outer'})[0]
links = []
for a in html.find_all('a', class_="tab-link-news"):
links.append(a['href'])
# Clean up news dataframe
news.columns = ['Date', 'News Headline']
news['Article Link'] = links
news = news.set_index('Date')
return news
except Exception as e:
return e
def get_insider():
try:
# Find insider table
insider = pd.read_html(str(html), attrs = {'class': 'body-table'})[0]
# Clean up insider dataframe
insider = insider.iloc[1:]
insider.columns = ['Trader', 'Relationship', 'Date', 'Transaction', 'Cost', '# Shares', 'Value ($)', '# Shares Total', 'SEC Form 4']
insider = insider[['Date', 'Trader', 'Relationship', 'Transaction', 'Cost', '# Shares', 'Value ($)', '# Shares Total', 'SEC Form 4']]
insider = insider.set_index('Date')
return insider
except Exception as e:
return e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment