0

I have a input of dictionary like this -

import pandas as p , numpy as n
dict={
's1':n.array([[1,2],[3,4]]),
's2':n.array([[5,6],[7,8]])
}
print(p.DataFrame(dict,index=[0]))

Expeced o/p

                     s1           s2
        0         [1,2]          [5,6]
        1         [3,4]          [7,8]

I'm getting an exception :data must be 1 dimensional , but when I pass 2d list in value I get the expected o/p. How to prevent this exception ??

Therii
  • 778
  • 1
  • 8
  • 16
  • 3
    An aside, I really suggest you stick with `pd` and `np`. These are universally recognised aliases. – roganjosh Aug 30 '18 at 15:18
  • 2
    Please don't shadow built-ins, use `d` instead of `dict`. – jpp Aug 30 '18 at 15:18
  • 1
    Also, please [edit your question](https://stackoverflow.com/posts/52100430/edit) to include your *desired* output. It's not clear what you need. – jpp Aug 30 '18 at 15:19

1 Answers1

2

Have a data type of list as individual element in Pandas dataframe is not supported. See thread here: https://github.com/pandas-dev/pandas/issues/9381

CathyQian
  • 1,081
  • 15
  • 30