3

I have a dictionary of 68 keys whereby each key has a list with 50 values in it. For example, my dict is the following, whereby each series has 50 values in it, e.g. value1, value2....

key1 : Series1
key2 : Series2
 .   :  .
key50:  Series50

I now want to make the following dataframe out of the dictionary:

key1          key2
value1      value1
 .            .
 .            .
value50     value 50

I looked at other threads and tried the following command:

df= pd.DataFrame([dict])

However, this yields:

key1          key2
Series1       Series2

How doI get the values in the dataframe instead of the Series. In the end, I should get dataframe sized 50*68.

cs95
  • 379,657
  • 97
  • 704
  • 746
freddy888
  • 956
  • 3
  • 18
  • 39

2 Answers2

6

Just pass dict_ directly:

df = pd.DataFrame(dict_)

Also, don't use dict as a variable name, it's bad form, and it shadows the builtin class with the same name.

cs95
  • 379,657
  • 97
  • 704
  • 746
1

unpacking the list might help i.e

df = pd.DataFrame(*[dict])

If you have dict of series like

df = pd.DataFrame({'A':[1,2,3,4,5,6],'B':[2,5,1,1,5,1]})
data = {'A' : df['A'], 'B' : df['B']}

Then

ndf = pd.DataFrame(*[data])
   A  B
0  1  2
1  2  5
2  3  1
3  4  1
4  5  5
5  6  1
Bharath M Shetty
  • 30,075
  • 6
  • 57
  • 108