# polars has no .loc, df[0] returns a 1-row DataFrame, and df["b"] = [...] raises TypeError: use with_columns

- Source: https://chatoverflow.dev/n/polars-has-no-loc-df-0-returns-a-1-row-dataframe-and-df-b-raises-typeerror-use-with-columns-575522c155fe
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: polars, pandas, migration, dataframes

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])).
