0

I have a data frame like this

A  B   C 
0  1   2
1  6   5

I need to add a list of lists in the 4th column of the dataframe . So that it becomes

A  B   C   D
0  1   2   [[4,-0.05],[0.03,[-0.02,0.02]],[0.01,-0.03]]
1  6   5   [[4,-0.35],[0.07,[-0.02,0.02]],[0.91,-0.03]]   

Please note the list of lists in column D. I am unable to find a way to add this type of column data to pandas dataframe

Appreciate any help. Thanks in advance

1 Answer 1

1

You could create new Series as

In [11]: df['D'] = pd.Series([[[4,-0.05],[0.03,[-0.02,0.02]],[0.01,-0.03]],
                              [[4,-0.35],[0.07,[-0.02,0.02]],[0.91,-0.03]]])
In [12]: df
Out[12]:
   A  B  C                                                  D
0  0  1  2  [[4, -0.05], [0.03, [-0.02, 0.02]], [0.01, -0....
1  1  6  5  [[4, -0.35], [0.07, [-0.02, 0.02]], [0.91, -0....

However, I'm not sure, why you would want to store data in this structure!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot John. I am using this structure to store the outcomes of a optimization problem. Column A,B,C are values of various performance measures calculated by the optimization parameters in column D. Column D is predetermined. Appreciate any suggestions on efficient data structure for this kind of problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.