【问题标题】:Pandas Dataframe plot rows vs columnsPandas Dataframe 绘制行与列
【发布时间】:2021-07-18 20:42:43
【问题描述】:

我想用足球比分绘制一个 DataFrame

Index | goals game 1| goals game 2| ....
Team 1| 2           | 3           | ....
Team 2| 4           | 1           | ....

所以我想为每支球队制定目标与比赛 - 我如何使用 pandas.DataFrame.plot 来做到这一点?

非常感谢!

【问题讨论】:

    标签: python pandas dataframe plot data-visualization


    【解决方案1】:
    >>> df = pd.DataFrame({'game 1':[4,5,2], 'game 2':[3,4,1], 'game 3':[3,2,2]}, index=['team a', 'team b', 'team c'])
    >>> df
            game 1  game 2  game 3
    team a       4       3       3
    team b       5       4       2
    team c       2       1       2
    
    >>> df.plot(kind='bar')
    

    plt.figure(figsize=(20,5))
    df.T.plot(kind='line',subplots=True, figsize=(4,6))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-25
      • 2017-12-09
      • 2018-04-16
      • 2016-07-02
      • 2016-11-02
      • 2017-03-24
      • 2015-06-12
      相关资源
      最近更新 更多