I am trying to use Polars with Rust. First thing I did was to read a tiny CSV file I created with Excel and print it. The output in the VSCode terminal appears full of strange characters:
df_astro: shape: (3, 2)
ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
Γöé A Γöå B Γöé
Γöé --- Γöå --- Γöé
Γöé i64 Γöå i64 Γöé
Γò₧ΓòÉΓòÉΓòÉΓòÉΓòÉΓò¬ΓòÉΓòÉΓòÉΓòÉΓòÉΓòí
Γöé 1 Γöå 4 Γöé
Γö£ΓòîΓòîΓòîΓòîΓòîΓö╝ΓòîΓòîΓòîΓòîΓòîΓöñ
Γöé 2 Γöå 5 Γöé
Γö£ΓòîΓòîΓòîΓòîΓòîΓö╝ΓòîΓòîΓòîΓòîΓòîΓöñ
Γöé 3 Γöå 6 Γöé
ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
Running the same program on the Command Prompt or PowerShell the output is Ok:
df_astro: shape: (3, 2)
┌─────┬─────┐
│ A ┆ B │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1 ┆ 4 │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 2 ┆ 5 │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 3 ┆ 6 │
└─────┴─────┘
Here is the code:
fn read_csv_to_dataframe(file_path: &str) -> Result<DataFrame,PolarsError> {
let df = CsvReader::from_path(file_path)?
.infer_schema(Some(5)) // Adjust the number of lines to read for schema inference
.has_header(true)
.with_delimiter(b',') // Specify the delimiter if it's not a comma
.with_ignore_parser_errors(true) // This might help if there are parsing issues
.finish()?;
Ok(df)
}
let df_astro = read_csv_to_dataframe(&file_astro);
match df_astro {
Ok(df) => println!("df_astro: {:#?}", df),
Err(err) => println!("Error reading astro data: {}", err),
}
Any suggestions on how to fix this?
I checked that the VSCode terminal is using UTF-8. I changed the font. I looked at the CSV file with Notepad++ and it did not have any strange characters, in each line numbers and CRLF at the end.
None of these things helped.