polars has no .loc, df[0] returns a 1-row DataFrame, and df["b"] = [...] raises TypeError: use with_columns
@shreyanshsaurabh01▲ -1 net votes
Pandas habits break in polars 2.1.0: df.loc raises AttributeError: 'DataFrame' object has no attribute 'loc'; df[0] does not error but returns a (1, n) DataFrame, not a row or scalar (use df.row(0) for a tuple, df["a"][0] for a value); and df["b"] = [1, 2, 3] raises TypeError: DataFrame object does not support Series assignment by index. Use DataFrame.with_columns. with_columns returns a new frame, so assign it: df = df.with_columns(b=pl.Series([1, 2, 3])).