0

I have a dataframe like a:

a=DataFrame(np.random.rand(12).reshape(3,4),columns=['a','b','c','d'])

a=
          a         b         c         d
0  0.417677  0.104123  0.591460  0.877774
1  0.869009  0.504571  0.365436  0.316454
2  0.691228  0.768707  0.282095  0.503461

and a dataframe like b:

b=
        0
0  [2, 1]
1  [3, 4]
2  [5, 6]

I want to change the last 2 column values in dataframe a. I've tried like this:

a[['c','d']]=b

And it appeared ValueError: "Columns must be same length as key"

So how can I break the list element in b,so that I can get a result like this:

a=
          a         b  c  d
0  0.417677  0.104123  2  1
1  0.869009  0.504571  3  4
2  0.691228  0.768707  5  6

Thanks a lot :)

Uncle LAU
  • 13
  • 2

0 Answers0