How add each element of a list as an element of a new column of a dataframe?

I have a list of list, like:

    X=[[1,1,2],[3,4,5],[8,1,9]]

and I have a dataframe with some columns, I will add a new column to my dataframe that each value of new column in each row is one of list of X, how can I do this?

to be more clear, for example, I have a dataframe in this image : enter image description here

and I have a list like X. then I want a new dataframe like: enter image description here

Upvotes: 0

Views: 786

Answers (1)

I'mahdi
I'mahdi

Reputation: 24049

try this:

df = pd.DataFrame({'a': {0: '1', 1: '2', 2: '3'},
                   'b': {0: 's', 1: 'n', 2: 'k'}})

X=[[1,1,2],[3,4,5],[8,1,9]]

df['new_col'] = X

df

output:

enter image description here

Upvotes: 1

Related Questions