首页 > 解决方案 > Rust polars: IntoSeries 特征没有为 &Series 实现

问题描述

我是 Rust 的新手,所以如果这个问题听起来很愚蠢,我很抱歉。我正在尝试深入polars了解如何在 Rust 中使用数据框和系列。我现在正在尝试读取数据框,提取一列,从数据框中删除该列并将该列重新添加回数据框:

use polars::prelude::*;
use polars::frame::DataFrame;
use polars::series::IntoSeries;

fn main() {
    // 1. read an input csv file and create a dataframe.             
    // 2. get a dataframe column 
    let series_column = df.column("COLUMN_NAME").unwrap(); 
    // 3. drop this column 
    df.drop_in_place("COLUMN_NAME"); 
    // 4. re-insert that column at index 0
    let new_df = df.insert_at_idx(0, series_column);

虽然我尝试了很多方法,但我总是有这个错误:

error[E0277]: the trait bound `&Series: IntoSeries` is not satisfied
  --> src/main.rs:78:36
   |
78 |     let new_df = df.insert_at_idx(0, series_column);
   |                                    ^^^^^^^^^^^^ the trait `IntoSeries` is not implemented for `&Series`
   |
   = help: the following implementations were found:
             <Series as IntoSeries>
}

看这help条线似乎有一个特征混淆,但我不知道如何解决这个问题。我哪里错了?谢谢

标签: dataframerustseriestraitsrust-cargo

解决方案


推荐阅读