After using my script my algorithms return the exptected outcome in a list of lists like this: pred=[[b,c,d],[b,a,u],...[b,i,o]]
I already have a dataframe that needs those values added in a new matching column.
The list is exactly x long like the other columns in the frame and I just need to create a new column with all the values of the lists.
However when I try to put the list into the column I get the error:
ValueError: Length of values does not match length of index
Looking at the data, it puts the entire list into one row instead of each entry in a new row.
EDIT:
All values in the list should be put in the column namend pred
sent token pred
0 a b
0 b c
0 b d
1 a b
1 b a
1 c u
Solution:
x = []
for _ in pred:
if _ is not None:
x += _
df_new = pd.DataFrame(df)
df_new["pred"] = list(itertools.chain.from_iterable(x))