I'm trying to plot a dataset contained in a dictionary:
my_dict = [{'A': [0.7315847607219574],
'B': [0.5681159420289855],
'C': [0.9999999999999997],
'D': [0.5793801642856945],
'E': [0.6867350732769776],
'F': [0.7336804366512104]},
{'A': [0.4758837897858464],
'B': [0.4219886317147244],
'C': [0.6206223617183635],
'D': [0.3911170612926995],
'E': [0.5159829508133175],
'F': [0.479838956092881]},
{'A': [0.7315847607219574],
'B': [0.5681159420289855],
'C': [0.9999999999999997],
'D': [0.5793801642856945],
'E': [0.6867350732769776],
'F': [0.7336804366512104]}]
then
df = pd.DataFrame(my_dict)
df.plot(kind="barh")
plt.show()
dtypes
is showing object type for all, and the syntax error TypeError: no numeric data to plot
I've exhausted most of my brain cells trying to figure this out but with no avail. All help will be appreciated.
CodePudding user response:
Extracting the number from the list does the job
import pandas as pd
import matplotlib.pyplot as plt
my_dict = [{'A': [0.7315847607219574],
'B': [0.5681159420289855],
'C': [0.9999999999999997],
'D': [0.5793801642856945],
'E': [0.6867350732769776],
'F': [0.7336804366512104]},
{'A': [0.4758837897858464],
'B': [0.4219886317147244],
'C': [0.6206223617183635],
'D': [0.3911170612926995],
'E': [0.5159829508133175],
'F': [0.479838956092881]},
{'A': [0.7315847607219574],
'B': [0.5681159420289855],
'C': [0.9999999999999997],
'D': [0.5793801642856945],
'E': [0.6867350732769776],
'F': [0.7336804366512104]}]
for entry in my_dict:
for k,v in entry.items():
entry[k] = v[0]
df = pd.DataFrame(my_dict)
df.plot(kind="barh")
plt.show()