I have a DataFrame with a string column that looks like this:
let df = df!(
"names" => &["None", "0", "1", "15", "1|2", "5 ??", "293 ", "XX"]);
I want to filter this down to only rows that are a single integer (multiple digits is fine) where that integer is greater than 0. I will also want to strip leading and trailing spaces, unless parse()
does that for me. (None of the numbers will be very high, nothing over 3000). In the above case, the indexes that get through the filter would be 2, 3, and 6.
I’ve found this other answer, but it doesn’t quite have what I need. The filtering page of the Polars user guide only shows very simple cases. Perhaps I haven’t found the right page of the docs?
This successfully removes all the “0”s, but I don’t want to have to exclude things one by one:
let filtered = df
.lazy()
.filter(col("names").neq(lit("0")))
.collect()?;
println!("filtered: {}", filtered);
Thanks in advance!