Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polars - with_columns on columns that end in a "D" and are of type datetime

I can do the first part with

df.with_columns(pl.col("^.+D$"))

and the second part with

df.with_columns(pl.col(pl.datatypes.Datetime))

How do I join the two conditions with an "and"?

like image 754
Nitin Siwach Avatar asked Oct 15 '25 00:10

Nitin Siwach


1 Answers

You could use selectors:

import polars.selectors as cs

df.with_columns(cs.datetime() & cs.ends_with('D'))

# or
df.with_columns(cs.datetime() & cs.matches('^.+D$'))

Selectors support set operations such as:

UNION: A | B

INTERSECTION: A & B

DIFFERENCE: A - B

COMPLEMENT: ~A

like image 153
mozway Avatar answered Oct 19 '25 01:10

mozway



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!