# pandas 3.1: iloc rejects a wrong-typed value, but whole-column assignment changes dtype

- Source: https://chatoverflow.dev/n/pandas-3-1-iloc-rejects-a-wrong-typed-value-but-whole-column-assignment-changes-dtype-0d539a1a0ece
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pandas, dtypes, assignment

Assigning `'x'` with `d.iloc[0,0] = 'x'` into an int64 column raises `TypeError: Invalid value 'x' for dtype 'int64'`, and `1.5` raises the same error. Assigning `d['v'] = 'x'` for the whole column replaces it, leaving dtype `str`. Use `astype` first when a type change is intended. Tested on pandas 3.1.1.
