EN VI
Posts (0)

No data results!

Please check back again in feature!

Questions (9)
2024-03-12 06:30:04
You can use DataFrame.with_row_index(): import polars as pl df = pl.DataFrame({"test": np.arange(1, 11)}) print( df.with_row_index() .with_columns( pl.when(pl.col("index") < 5)...
Tags: python pandas dataframe
2024-03-12 22:00:05
Not sure which output exactly you're expecting, but here's an example of incrementing the counter only at rows which meet the criteria, using cum_sum(): df.with_columns( pl.when(pl.col('code') ==...
2024-03-13 03:00:10
The reason that your sample code doesn't work as expected is that Polars write_excel() applies a cell format for numbers and that overwrites the row format. You can control column or dtype formatting...
2024-03-13 20:30:05
You might be searching for pl.int_range, potentially combined with pl.Expr.over. import polars as pl df = pl.DataFrame({ "group": ["A", "A", "A", "B", "B", "C"], }) df.with_columns(pl.int_range(...
2024-03-15 04:00:17
You can keep the Event objects by passing return_dtype=pl.Object df.select(pl.col("events").map_elements(event_table)) shape: (5, 1) ┌───────────────────────────────────┐ │ events...
2024-03-15 07:00:06
While the solution using the walrus operator works. It is probably more idiomatic and cleaner to use an pl.when().then() construct in conjunction with pl.int_range() to create the event_id. ( df...
Tags: python pandas dataframe
2024-03-15 10:00:05
I think you found out a very unique/interesting and clever solution. Consider also just iterating over columns: df.select(column / scalars[column.name] for column in df.iter_columns()) or df.select(p...
Tags: python numpy python-polars
2024-03-15 17:00:08
You could install duckdb-engine, and write the database using the connection URI string. df.write_database( table_name='test_table', connection="duckdb:///scratch.db", ) Reading the data back...
Tags: python uri python-polars
2024-03-16 14:00:05
You can compute the max per group over df1, then clip df2: out = df2.with_columns( pl.col('index').clip( upper_bound=df1.select(pl.col('index').max().over('group'))['index'] ) ) Outp...

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login