Issue
I have a dic of list type. like this :
{'key': '3d animator',
'Results': [{'freelance artist': 1}, {'3d artist': 2}]},
{'key': '3d artist',
'Results': [{'sous chef': 1},
{'3d animator': 2},
{'art director': 1},
{'artist': 1}]},
{'key': '3d designer',
'Results': [{'network administrator': 1}, {'None': 1}]}
can I plot a graph for each key
, and show by hist the frequency of the values
('Results)
? for example for key= 3d animator
, a hist chart where in the horizontal axis I have 'freelance artist'
and 3d artist
and in the vertical axis their frequency 1
and 2
?
Solution
First suggestion is to reformat your data:
my_list = [{'key': '3d animator',
'Results': [{'freelance artist': 1}, {'3d artist': 2}]},
{'key': '3d artist',
'Results': [{'sous chef': 1},
{'3d animator': 2},
{'art director': 1},
{'artist': 1}]},
{'key': '3d designer',
'Results': [{'network administrator': 1}, {'None': 1}]}]
Assuming each key in subdict lists is unique:
final_dict = {elem["key"]:{k: v for d in elem["Results"] for k, v in d.items()} for elem in my_list}
Then plot each value (dict) of the outer dict (dataset):
import matplotlib.pyplot as plt
for k,v in final_dict.items():
plt.figure()
plt.title(k)
plt.bar(list(v.keys()), v.values())
plt.show()
This plots a graph for each key of the dataset (if that's your need).
Answered By - frab
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.