79767682

Date: 2025-09-17 18:25:48
Score: 1
Natty:
Report link

The answer from Michael Hays is great, just adding as a tip for other facing the same issue as me:

if you have a column duplicated in your df, you will get a "ValueError: Must have equal len keys and value when setting with an iterable" even using `at`.

df = pd.DataFrame({'A': [12, 23]})
df2 = pd.concat([df, df], axis=1)
df2['B'] = pd.NA

print(df2)
    A   A     B
0  12  12  <NA>
1  23  23  <NA>

print(df2.dtypes)
A     int64
A     int64
B    object
dtype: object

df2.at[1, 'B'] = ['m', 'n']
# ValueError: Must have equal len keys and value when setting with an iterable

The solution is of course not to have duplicated columns.

Reasons:
  • Whitelisted phrase (-1): solution is
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): facing the same issue
  • Low reputation (0.5):
Posted by: Maxime