简体   繁体   中英

Python Pandas: ValueError: Must have equal len keys and value when setting with an iterable

I have a DataFrame that I want to change using

df.loc[rowId,colId] = myDict 

to assign a dict to the entry [rowId,colId]. As a result I get following error:

ValueError: Must have equal len keys and value when setting with an iterable

Setting

df.loc[rowId,colId] = 0

works, In my pinion the style to assign the value in the first approach is the right one? so what is wrong?

It is possible by adding list :

df.loc[rowId,colId] = [myDict]

But for better performance in pandas is best working in pandas only with scalars.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM