2

Following my previous question , all is working well but when the list it's long it's showing this erreur, This is a simple of d :

['Houda Golf & Aquapark Novostar Monastir ', " {'All Inclusive soft': ('202', '175', '15%'), 'Demi Pension': ('161', '140', '15%'), 'Petit Dejeuner': ('137', '119', '15%'), 'DP plus': ('237', '119', '15%')}"]

Anyone knows how can i fix it ? thank you in advance.

NB: I've tried several solutions from responses here but they hasn't work for me

enter image description here

HiFAR
  • 48
  • 1
  • 13

1 Answers1

1

Try to convert the values of dictionary to list if they are scalars:

from ast import literal_eval


vals = literal_eval(d[1].strip())
df = pd.DataFrame(
    {k: v if isinstance(v, (list, tuple)) else [v] for k, v in vals.items()}
)
print(df)
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91