Heim  >  Fragen und Antworten  >  Hauptteil

Python – Pandas-Gruppierung nach Bedingungsdiagramm

Wie zeichne ich ein Balkendiagramm mit dem Namen als Abszisse und der Punktzahl als Ordinate?

某草草某草草2678 Tage vor1050

Antworte allen(1)Ich werde antworten

  • 仅有的幸福

    仅有的幸福2017-06-20 10:07:45

    試試

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

    基本pandas 可視化原則是,使用pivot 或melt搞出製圖需要的表格格式。

    下列是我跑的代碼(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()
    

    結果:

    Antwort
    0
  • StornierenAntwort