Skip to content
Advertisement

How to create a Pandas Dataframe from a dictionary with values into one column?

Suppose dict = {'A':{1,2,4}, 'B':{5,6}}, How to create a Pandas Dataframe like this:

    Key  Value
0   'A'  {1,2,4}
1   'B'  {5,6}

Advertisement

Answer

Try:

dct = {"A": {1, 2, 4}, "B": {5, 6}}

df = pd.DataFrame({"Key": dct.keys(), "Value": dct.values()})
print(df)

Prints:

  Key      Value
0   A  {1, 2, 4}
1   B     {5, 6}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement