将CSV文件读入带Rust的Polars Dataframe

1aaf6o9v  于 2023-01-26  发布在  其他
关注(0)|答案(1)|浏览(234)

我想将CSV文件读入Polars Dataframe 。
official documentation复制代码无法与货物一起运行。

use polars::prelude::*;
use std::fs::File;

fn example() -> Result<DataFrame> {
    let file = File::open("iris.csv").expect("could not open file");

    CsvReader::new(file)
            .infer_schema(None)
            .has_header(true)
            .finish()
}

fn main() {
    let df = example();
    println!("{:?}", df);
}

导致

$ cargo run
   Compiling project v0.1.0
error[E0107]: this enum takes 2 generic arguments but 1 generic argument was supplied
 --> src/main.rs:4:17
  |
4 | fn example() -> Result<DataFrame> {
  |                 ^^^^^^ --------- supplied 1 generic argument
  |                 |
  |                 expected 2 generic arguments
  |
help: add missing generic argument
  |
4 | fn example() -> Result<DataFrame, E> {
  |                                 +++

For more information about this error, try `rustc --explain E0107`.
error: could not compile `eon-playground` due to previous error
2g32fytz

2g32fytz1#

您正在阅读一个旧版本的文档(可以通过顶部的“转到最新版本”看到),在这个版本中,polars::prelude导出了一个别名Result,现在重命名为PolarsResultthe updated example为:

use polars_core::prelude::*;
use polars_io::prelude::*;
use std::fs::File;

fn example() -> PolarsResult<DataFrame> {
    CsvReader::from_path("iris_csv")?
            .has_header(true)
            .finish()
}

相关问题