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/employees.py
Pietro Rodolfo Masera 709440c1dd Employees graph done
2023-05-24 11:56:28 +02:00

21 lines
909 B
Python

import os
import pandas as pd
import numpy as np
ROOT_PATH: str = os.path.join(os.path.dirname(__file__), '..', '..')
def get_employees(tickers: list[str]) -> list[dict]:
employees_df = pd.read_csv(ROOT_PATH + '/Elaborated_Data/employees_over_time.csv', index_col=[0])
s_tickers = pd.Series(tickers)
employees_df = employees_df.loc[employees_df['Ticker'].isin(s_tickers), :]
dates = [str(date) + '-01-01' for date in range(2012, 2023 + 1)]
for i, date in enumerate(dates):
employees_df[date] = employees_df['Employees_over_time'].copy().apply(lambda x: int(eval(str(x))[i]))
employees_df = pd.melt(employees_df, id_vars=['Ticker'], value_vars=dates, var_name='year').reset_index(drop=True)
employees_df = employees_df.pivot(index='year', columns='Ticker', values='value').reset_index(drop=False)
return employees_df.replace({ np.nan: None }).to_dict('records')