Last active
October 27, 2021 23:30
-
-
Save marcosan93/8c28210717d9446abe30cc4ef0978f3c to your computer and use it in GitHub Desktop.
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
| 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