Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Last active October 27, 2021 23:30
Show Gist options
  • Select an option

  • Save marcosan93/8c28210717d9446abe30cc4ef0978f3c to your computer and use it in GitHub Desktop.

Select an option

Save marcosan93/8c28210717d9446abe30cc4ef0978f3c to your computer and use it in GitHub Desktop.
def formatFundamentals(ticker, dropna=False):
"""
Formats the given ticker's fundamental and price data. Cleans up the data by dropping
any empty/nan values if requested.
"""
# Getting fundamental data
fund_data = getFundamentals(ticker)
# Getting accompanying price data
df = getPrices(fund_data, ticker)
# Dropping if all items are na in respective row
df = df.dropna(how='all')
if dropna:
# Dropping mostly nan columns and rows if requested
df = df.dropna(
axis=0,
thresh=round(df.shape[0]*.5) # If 50% of the values in the row are Nans, drop the whole row
).dropna(
axis=1,
thresh=round(df.shape[1]*.5) # If 50% of the values in the columns are Nans, drop the whole column
)
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment