Panda Dataframe from Dict with different length value

Viewed 1423

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]
1 Answers

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]
Related