i have a dataframe that look like this
i would like to convert the first column 'time' with date strings into a column with only numbers in format of "YYYYMMDD"(e.g.: 20230531) in u64.
i tried building up a function to do this but i am struggling and espcially in how to remove the hyphens in date strings.
pub fn convert_str_to_num(df: &DataFrame) -> Result<DataFrame, PolarsError> {
let mut final_df = df.clone();
let col_name = String::from("time");
let time_col = df.column(col_name.as_str())?;
let mut new_time_col = time_col.clone().replace("-", "")?;
// replace the old column with the new one
final_df.replace(col_name.as_str(), new_time_col.as_mut())?;
Ok(final_df)
}
somehow this returns
error[E0599]: no method named `replace` found for struct `polars::prelude::Series` in the current scope
--> src/main.rs:13:45
|
13 | let mut new_time_col = time_col.clone().replace("-", "")?;
| ^^^^^^^ method not found in `Series`