Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 448

Polars - How to replace the value of a specific row and column in df (ex. df[3,4]=12) with Polars Expression?

$
0
0

I know that Polars Expressions are column-wise parallelized for reading and calculating and input/change data in a DataFrame.So, it's very fast...

However, I cannot find the Polars Expression that change a specific value of row and column as df[1,'a']=12How can I do it?

Below is how I would like to do it.

import polars as pldf = pl.DataFrame(    {"a": [1,2,3,4,5,6,7,8],"b": [8,9,0,1,2,3,4,5],"c": [0,0,0,0,0,0,0,0],"d": [0,0,0,0,0,0,0,0],    })df = df.with_columns(pl.all().cast(pl.Float64))df[7,'c']=12   df[7,'d']=15# I want this to below way that Polars Expressions# => df.select(?)(        pl.col('c').row(7) = 12        pl.col('d').row(7) = 15     )print(df)
shape: (8, 4)┌─────┬─────┬──────┬──────┐│ a   ┆ b   ┆ c    ┆ d    ││ --- ┆ --- ┆ ---  ┆ ---  ││ f64 ┆ f64 ┆ f64  ┆ f64  │╞═════╪═════╪══════╪══════╡│ 1.0 ┆ 8.0 ┆ 0.0  ┆ 0.0  ││ 2.0 ┆ 9.0 ┆ 0.0  ┆ 0.0  ││ 3.0 ┆ 0.0 ┆ 0.0  ┆ 0.0  ││ 4.0 ┆ 1.0 ┆ 0.0  ┆ 0.0  ││ 5.0 ┆ 2.0 ┆ 0.0  ┆ 0.0  ││ 6.0 ┆ 3.0 ┆ 0.0  ┆ 0.0  ││ 7.0 ┆ 4.0 ┆ 0.0  ┆ 0.0  ││ 8.0 ┆ 5.0 ┆ 12.0 ┆ 15.0 │└─────┴─────┴──────┴──────┘

Viewing all articles
Browse latest Browse all 448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>