This repository has been archived on 2023-06-18. You can view files and clone it, but cannot push or open issues or pull requests.
va-project/backend/api/eps.py
Tommaso Verzegnassi e68a6eeb36 things occurred
2023-05-29 13:38:31 +02:00

17 lines
No EOL
700 B
Python

import os
import pandas as pd
import numpy as np
from scraper.top100_extractor import programming_crime_list
from typing import Optional
DF_EPS_PATH: str = os.path.join(os.path.dirname(__file__), '..', '..', 'Elaborated_Data', 'eps_quarterly_bar_chart.csv')
def get_eps(tickers: list[str]) -> list[dict]:
df = pd.read_csv(DF_EPS_PATH)
ticker_series = pd.Series(tickers)
df = df.loc[df.symbol.isin(ticker_series), :] \
.rename(columns={"epsActual": "quarterlyEps", "symbol": "ticker"}) \
.reset_index(drop=True)
df = df.pivot(index='quarter', columns='ticker', values='quarterlyEps').reset_index(drop=False)
return df.replace({ np.nan: None }).to_dict('records')