Kev
Kev

Reputation: 13

Convert List to Python dataframe

I have tried below code to convert my list object to dataframe, however, I keep getting error.

Please can someone advise?

Code:

  newframe = pd.DataFrame(np.array(basket).reshape(len(basket), -1),  
                 columns = ['currency', 'weights' , 'ric'])

ERROR :

ValueError: Shape of passed values is (1, 55), indices imply (3, 55)

List object:

<class 'list'>: [{'currency': 'EUR', 'weight': 806311901, 'ric': '_DIVISOR'},  
{'currency': 'EUR', 'weight': 89440570.0, 'ric': 'AFXG.DE'},  
{'currency': 'DKK', 'weight': 217059600.0, 'ric': 'AMBUb.CO'},  
{'currency': 'EUR', 'weight': 37692508.0, 'ric': 'ARGX.BR'},  
{'currency': 'GBp', 'weight': 1267101448.0, 'ric': 'AZN.L'},  
{'currency': 'EUR', 'weight': 932551965.0, 'ric': 'BAYGn.DE'}, 
{'currency': 'CHF', 'weight': 55400000.0, 'ric': 'BION.S'}]

Thanks for your help.

Upvotes: 1

Views: 163

Answers (1)

vi_me
vi_me

Reputation: 408

df = pd.DataFrame(list_of_dicts)

Upvotes: 2

Related Questions