1

I would like to convert dictionary of Lists into Pandas dataframe. While there are many (which can lead to downvote) similar topic such as OP1,OP2, OP3, OP4, OP5, OP6, but none of the suggestion worked for me. Off all, the closes suggestion I got was from the OP7. However, the following error was shot

AttributeError: 'list' object has no attribute 'items'

The mock up dictionary that represent the actual dictionary are as below:

x_00 = [{ "brand": "Ford","model": "Mustang","year": 1964},
            {  "brand": "Fx","model": "Musxxg","year": 1900},
          {"brand" : "Foyy", "model": "Musyyy", "year": 2020 }]

x_01= [{ "brand": "Forr","model": "Musrr","year": 1900},
            {  "brand": "Frr","model": "Musrr","year": 1955},
          {"brand" : "Forr", "model": "Musrr", "year": 2025 }]

x_02= [{ "brand": "Fogg","model": "Musgg","year": 1902},
            {  "brand": "Fgg","model": "Musgg","year": 1922},
          {"brand" : "Fogg", "model": "Musgg", "year": 2022 }]

CombineAll=[x_00,x_01,x_02]

As per suggestion from the thread Link , the following code was realized.

df = pd.concat([pd.DataFrame.from_dict(x, orient='index') for x in CombineAll])

But as mentioned above, error was thrown out.

Really appreciate for any hint or direction to any thread that I might miss look.

I am glad to delete this thread if there is possible duplicate!

mpx
  • 3,081
  • 2
  • 26
  • 56
  • 1
    `pd.concat([*map(pd.DataFrame,CombineAll)],ignore_index=True)` ? – anky Apr 18 '20 at 16:28
  • ```df = pd.concat([pd.DataFrame(data=x) for x in CombineAll])``` works as x is a list, not dict – rajarshig Apr 18 '20 at 16:33
  • combineAll = x_00 + x_01+ x_02 , df= pd.Dataframe(combinAll) – Rajat Mishra Apr 18 '20 at 16:37
  • `pd.DataFrame(x_00+x_01+x_02)` or if you have a list of list: `pd.DataFrame(*reduce(lambda cum_list, new_list: cum_list + new_list,CombineAll ))` – ansev Apr 18 '20 at 16:38
  • Thanks for the suggestion @anky. I check the other thread and found that the solution provided there is different than your. Because of this, I think you should post your suggestion as an answer rather than comment to get the proper credit! – mpx Apr 18 '20 at 16:39
  • Also, is it still dont consider my thread as a duplicate thread compare to the said other thread? mmm – mpx Apr 18 '20 at 16:39
  • 1
    @balandongiv its essentially the same question :) best not to have multiple questions for the same purpose? piR has commented down the answer the same as mine as well. – anky Apr 18 '20 at 16:44
  • 1
    noted @anky. Thanks btw – mpx Apr 18 '20 at 16:45

0 Answers0