This commit is contained in:
Palash Tyagi
2024-11-19 01:15:52 +00:00
parent 2b55b199d6
commit 1ea698a1e2
5 changed files with 75 additions and 268 deletions

View File

@@ -4,10 +4,14 @@ use polars::prelude::*;
use std::collections::HashMap;
use std::error::Error;
#[allow(unused_imports)]
use std::f32::consts::E;
/// The required columns for a Quantamental DataFrame.
const QDF_INDEX_COLUMNS: [&str; 3] = ["real_date", "cid", "xcat"];
/// Pivots a dataframe to a format where each ticker a column.
#[allow(dead_code)]
pub fn pivot_dataframe_by_ticker(
df: DataFrame,
metric: Option<String>,
@@ -24,7 +28,7 @@ pub fn pivot_dataframe_by_ticker(
metric = df.get_column_names()[3].to_string();
}
let mut new_df = df.clone();
// let mut new_df = df.clone();
// keep only the index columns and the metric column
let mut keep_cols = QDF_INDEX_COLUMNS
.to_vec()
@@ -33,7 +37,9 @@ pub fn pivot_dataframe_by_ticker(
.collect::<Vec<String>>();
keep_cols.push(metric.clone());
new_df = new_df.select(keep_cols)?;
return Err("Not implemented".into());
// new_df = new_df.select(keep_cols)?;
// let ticker_col = get_ticker_column_for_quantamental_dataframe(&new_df)?;
// new_df.with_column(ticker_col)?;
@@ -42,9 +48,11 @@ pub fn pivot_dataframe_by_ticker(
// let dates_col = df.column("real_date")?;
Ok(df)
// Ok(df)
}
/// Splits a dataframe by ticker.
#[allow(dead_code)]
fn split_df_by_tickers(df: &DataFrame) -> Result<HashMap<String, DataFrame>, Box<dyn Error>> {
check_quantamental_dataframe(df)?;