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

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

df = pd.DataFrame(data={'A': [1, 2, 3], 'B': ['x', 'y', 'z']})

df.at[1, 'B'] = ['m', 'n']

df =
    A   B
0   1   x
1   2   [m, n]
2   3   z

Here is what the above code is Doing:
1. Create a dataframe with two columns, A and B.
2. Set the value of the second row of column B to a list of two strings.
3. Print the dataframe.

The result is that the second row of column B is now a list of two strings.

Similar Posts