mirror of
https://github.com/NexVeridian/ark-invest-api-rust-data.git
synced 2025-09-02 09:59:12 +00:00
format europe arkfundsio
This commit is contained in:
parent
952014f88f
commit
9696094a15
1 changed files with 33 additions and 16 deletions
39
src/util.rs
39
src/util.rs
|
@ -351,10 +351,35 @@ impl Ark {
|
||||||
Ok(df.into())
|
Ok(df.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn df_format_europe_arkfundsio(df: DF) -> Result<DF, Error> {
|
||||||
|
let mut df = df.collect()?;
|
||||||
|
|
||||||
|
if df
|
||||||
|
.get_column_names()
|
||||||
|
.eq(&["fund", "date", "company", "cusip", "weight", "weight_rank"])
|
||||||
|
{
|
||||||
|
_ = df.drop_in_place("fund");
|
||||||
|
_ = df.drop_in_place("weight_rank");
|
||||||
|
|
||||||
|
df = df
|
||||||
|
.lazy()
|
||||||
|
.with_columns([
|
||||||
|
Series::new("ticker", [None::<&str>]).lit(),
|
||||||
|
Series::new("market_value", [None::<i64>]).lit(),
|
||||||
|
Series::new("shares", [None::<i64>]).lit(),
|
||||||
|
Series::new("share_price", [None::<i64>]).lit(),
|
||||||
|
])
|
||||||
|
.collect()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(df.into())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn df_format(df: DF) -> Result<DF, Error> {
|
pub fn df_format(df: DF) -> Result<DF, Error> {
|
||||||
let mut df = Self::df_format_21shares(df)?.collect()?;
|
let mut df = Self::df_format_21shares(df)?.collect()?;
|
||||||
df = Self::df_format_arkvx(df.into())?.collect()?;
|
df = Self::df_format_arkvx(df.into())?.collect()?;
|
||||||
df = Self::df_format_europe(df.into())?.collect()?;
|
df = Self::df_format_europe(df.into())?.collect()?;
|
||||||
|
df = Self::df_format_europe_arkfundsio(df.into())?.collect()?;
|
||||||
|
|
||||||
if df.get_column_names().contains(&"market_value_($)") {
|
if df.get_column_names().contains(&"market_value_($)") {
|
||||||
df = df
|
df = df
|
||||||
|
@ -375,18 +400,13 @@ impl Ark {
|
||||||
.collect()?;
|
.collect()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if df.rename("market_value_($)", "market_value").is_ok() {}
|
|
||||||
// if df.rename("market value ($)", "market_value").is_ok() {}
|
|
||||||
// if df.rename("weight_(%)", "weight").is_ok() {}
|
|
||||||
// if df.rename("weight (%)", "weight").is_ok() {}
|
|
||||||
// if df.rename("CUSIP", "cusip").is_ok() {}
|
|
||||||
|
|
||||||
if df.get_column_names().contains(&"fund") {
|
if df.get_column_names().contains(&"fund") {
|
||||||
_ = df.drop_in_place("fund");
|
_ = df.drop_in_place("fund");
|
||||||
}
|
}
|
||||||
if df.get_column_names().contains(&"weight_rank") {
|
if df.get_column_names().contains(&"weight_rank") {
|
||||||
_ = df.drop_in_place("weight_rank");
|
_ = df.drop_in_place("weight_rank");
|
||||||
}
|
}
|
||||||
|
|
||||||
if df.get_column_names().contains(&"") {
|
if df.get_column_names().contains(&"") {
|
||||||
let mut cols = df.get_column_names();
|
let mut cols = df.get_column_names();
|
||||||
cols.retain(|&item| !item.is_empty());
|
cols.retain(|&item| !item.is_empty());
|
||||||
|
@ -689,16 +709,13 @@ impl Ark {
|
||||||
|
|
||||||
let mut df = Reader::Json.get_data_url(url)?;
|
let mut df = Reader::Json.get_data_url(url)?;
|
||||||
df = match source {
|
df = match source {
|
||||||
Some(Source::ArkFundsIoIncremental) | Some(Source::ArkFundsIoFull) => {
|
Some(Source::ArkFundsIoIncremental) | Some(Source::ArkFundsIoFull) => df
|
||||||
df = df
|
|
||||||
.column("holdings")?
|
.column("holdings")?
|
||||||
.clone()
|
.clone()
|
||||||
.explode()?
|
.explode()?
|
||||||
.struct_()?
|
.struct_()?
|
||||||
.clone()
|
.clone()
|
||||||
.unnest();
|
.unnest(),
|
||||||
df
|
|
||||||
}
|
|
||||||
_ => df,
|
_ => df,
|
||||||
};
|
};
|
||||||
Ok(df)
|
Ok(df)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue