2
Dict = {'type': 'book', 'text_eng': 'National accounts', 'text': 'Volkswirtschaftliche Gesamtrechnungen', 'anchor': 'GESAMTVOLK'}
pd.DataFrame(Dict)
pd.DataFrame.from_dict(Dict)

Above script throws error: "ValueError: If using all scalar values, you must pass an index"

I need Dictionary Keys as DataFrame Columns & Dictionary Values in rows.

Below script working fine as Dictionary Values added as List

Dict = {'type': ['book'], 'text_eng': ['National accounts'], 'text': ['Volkswirtschaftliche Gesamtrechnungen'], 'anchor': ['GESAMTVOLK']}

Please let me know how to achiev this?

Learnings
  • 2,780
  • 9
  • 35
  • 55

1 Answers1

1

Use:

import pandas as pd

D = {'type': 'book', 'text_eng': 'National accounts', 'text': 'Volkswirtschaftliche Gesamtrechnungen', 'anchor': 'GESAMTVOLK'}
a = pd.DataFrame([D])
print(a)

Output:

       anchor                                   text           text_eng  type
0  GESAMTVOLK  Volkswirtschaftliche Gesamtrechnungen  National accounts  book
Rakesh
  • 81,458
  • 17
  • 76
  • 113