python - pandas group by condition charting
某草草
某草草 2017-06-20 10:05:45
0
1
1071

How to draw a bar chart with the name as the abscissa and the score as the ordinate?

某草草
某草草

reply all(1)
仅有的幸福

Try it

df.pivot('name', 'subject', 'score').plot.bar()

The basic pandas visualization principle is to use pivot or melt to create the table format required for charting.

The following is the code I ran (Jupyter Notebook)

% matplotlib inline
data = [ {"name":"abc", "subject":"A", "score":40}, {"name":"abc", "subject":"B", "score":60}, {"name":"abc", "subject":"C", "score":40},
        {"name":"xyz", "subject":"A", "score":10}, {"name":"xyz", "subject":"B", "score":90}, {"name":"xyz", "subject":"C", "score":30}]
df = pd.DataFrame(data)
df.pivot('name', 'subject', 'score').plot.bar()

Result:

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!