[Python] Assign a list in a pandas dataframe cell: ValueError: Must have equal len keys and...

Discussão em 'Python' iniciado por Stack, Novembro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I was trying to

    df.at[100, 'subjects']


    The result is

    []


    which indicates the index is unique.

    But when I tried to replace the empty list to a new one:

    df.at[100, 'subjects'] = [1,2,3]


    the error occurred.

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


    I met several similar cases when I tried to assign a list value to a specific cell in pandas dataframe. But I couldn't repeat this error, sometimes the valueError showed up and at other times it was just fine. I really cannot explain the reason that has caused the difference..

    Thanks in advance!

    Continue reading...

Compartilhe esta Página