4

I want to create a dataframe from my dictionary. Each value for the key is actually a array with multiple value in it.

>>> my_dict = {"a": [1,2,3], "b": [0], "c": [3,5] }

I want all the keys in a column 1 and entire value array in the column 2.

I've tried this post. Creating dataframe from a dictionary where entries have different lengths

But this solution separates all the value from the key to multiple columns.

Expected DF should look like this

>>> df 
      Key_Column   Value_Column
          a            [1,2,3]
          b            [0]
          c            [3,5]
SwagZ
  • 759
  • 1
  • 9
  • 16
  • You have an answer that's correct, but I think you should reconsider *why* you want to store data like this. DataFrames aren't meant to store lists. – user3483203 Jan 08 '19 at 01:36

1 Answers1

7

Check with Series

pd.Series(my_dict).rename_axis('Key_Column').reset_index(name='Value_Column')

  Key_Column Value_Column
0          a    [1, 2, 3]
1          b          [0]
2          c       [3, 5]
cs95
  • 379,657
  • 97
  • 704
  • 746
BENY
  • 317,841
  • 20
  • 164
  • 234
  • Right on, thank you so much for the help! I will accept this as the answer after the default 10 mins cool down. – SwagZ Jan 08 '19 at 00:55