I have an already set Pandas Dataframe that contains an image path and I need to add a column to it where each cell should contain a multidimensional array (representing that image).
Here an example:
import pandas as pd
import numpy as np
df = pd.DataFrame(data=[["test.png","dog.png"],[3,4]], columns=["path","B"])
# creating a new empty column
df = df.assign(image=np.nan)
image = # reading image path from row 1
df.iloc[1, df.columns.get_loc("image")] = image
but I keep obtaining the error: ValueError: Must have equal len keys and value when setting with an ndarray
.
How can I fix that? I've already tried to follow this but it didn't work for me.
Just to be clear, in my real dataframe the image field on n-th row depends on the value of path on n-th row.
Expected result:
path B image
0 "test.png" 2 NaN
1 "dog.png" 4 [[1,2,...], [255,255,...], ...]