dictionary - Python / Pandas - Turning a list with inner dictionaries into a DataFrame -
i'm new pandas , need turn list inner dictionaries dataframe
below example of list:
[('fwd1', {'score': 1.0, 'prediction': 7.6, 'mape': 2.37}), ('fwd2', {'score': 1.0, 'prediction': 7.62, 'mape': 2.57}), ('fwd3', {'score': 1.0, 'prediction': 7.53, 'mape': 2.54})] i this:
prediction mape score date fwd1 7.6 2.37 1 fwd2 7.62 2.57 1 fwd3 7.53 2.54 1 anyone available enlight journey?
you can convert list of tuples dict first , create dataframe. unfortunately, in structure, index , columns need swapped desired output, need transpose it.
assume x list:
in [18]: dict(x) out[18]: {'fwd1': {'mape': 2.37, 'prediction': 7.6, 'score': 1.0}, 'fwd2': {'mape': 2.57, 'prediction': 7.62, 'score': 1.0}, 'fwd3': {'mape': 2.54, 'prediction': 7.53, 'score': 1.0}} in [19]: pd.dataframe(dict(x)) out[19]: fwd1 fwd2 fwd3 mape 2.37 2.57 2.54 prediction 7.60 7.62 7.53 score 1.00 1.00 1.00 in [20]: pd.dataframe(dict(x)).t out[20]: mape prediction score fwd1 2.37 7.60 1 fwd2 2.57 7.62 1 fwd3 2.54 7.53 1
Comments
Post a Comment