使用groupby函数画图的问题

我有一个如下所示的数据框:-


df1.set_index('date', inplace=True)


date        symbol   roe

2019-12-31  FMC 21.2189

2018-12-31  FMC 16.7456

2017-12-31  FMC -4.9167

2016-12-31  FMC 6.5580

2015-12-31  FMC -11.1408

2014-12-31  FMC 19.6675

2013-12-31  FMC 23.6372

2012-12-31  FMC 29.7916

2011-12-31  FMC 32.2291

2010-12-31  FMC 18.3737

2009-12-31  FMC 22.6811

2008-12-31  FMC 35.8547

2007-12-31  FMC 15.6253

2006-12-31  FMC 14.2645

2005-12-31  FMC 11.2999

2019-12-31  VMC 21.2189

2018-12-31  VMC 16.7456

2017-12-31  VMC -4.9167

2016-12-31  VMC 6.5580

2015-12-31  VMC -11.1408

2014-12-31  VMC 19.6675

2013-12-31  VMC 23.6372

2012-12-31  VMC 29.7916

2011-12-31  VMC 32.2291

2010-12-31  VMC 18.3737

2009-12-31  VMC 22.6811

2008-12-31  VMC 35.8547

2007-12-31  VMC 15.6253

2006-12-31  VMC 14.2645

2005-12-31  VMC 11.2999

2019-12-31  APD 21.2189

2018-12-31  APD 16.7456

2017-12-31  APD -4.9167

2016-12-31  APD 6.5580

2015-12-31  APD -11.1408

2014-12-31  APD 19.6675

2013-12-31  APD 23.6372

2012-12-31  APD 29.7916

2011-12-31  APD 32.2291

2010-12-31  APD 18.3737

2009-12-31  APD 22.6811

2008-12-31  APD 35.8547

2007-12-31  APD 15.6253

2006-12-31  APD 14.2645

2005-12-31  APD 11.2999

2019-12-31  MLM 21.2189

2018-12-31  MLM 16.7456

2017-12-31  MLM -4.9167

2016-12-31  MLM 6.5580

2015-12-31  MLM -11.1408

2014-12-31  MLM 19.6675

2013-12-31  MLM 23.6372

2012-12-31  MLM 29.7916

2011-12-31  MLM 32.2291

2010-12-31  MLM 18.3737

2009-12-31  MLM 22.6811

2008-12-31  MLM 35.8547

2007-12-31  MLM 15.6253

2006-12-31  MLM 14.2645

2005-12-31  MLM 11.2999

2019-12-31  NEM 21.2189

2018-12-31  NEM 16.7456

2017-12-31  NEM -4.9167

2016-12-31  NEM 6.5580

2015-12-31  NEM -11.1408

2014-12-31  NEM 19.6675

2013-12-31  NEM 23.6372

2012-12-31  NEM 29.7916

2011-12-31  NEM 32.2291

2010-12-31  NEM 18.3737

2009-12-31  NEM 22.6811

2008-12-31  NEM 35.8547

2007-12-31  NEM 15.6253

2006-12-31  NEM 14.2645

2005-12-31  NEM 11.2999

我已经将日期设置为索引,并使用 groupby 函数来绘制图表,代码如下所示:-


df1.groupby('symbol')['roe'].plot(figsize = (8, 6), legend=True)

输出仅显示 1 行。除了输出将显示 5 个不同的图形之外,因为数据框中有 5 个不同的符号,我可以知道如何解决这个问题吗?


慕尼黑8549860
浏览 104回答 1
1回答

开满天机

您可能需要检查数据的生成/来源。您的绘图代码完全有效,产生:这似乎是五个相同的地块。快速透视表明所有符号确实相同:roedf.pivot('date','symbol','roe')输出:symbol          APD      FMC      MLM      NEM      VMCdate                                                   2005-12-31  11.2999  11.2999  11.2999  11.2999  11.29992006-12-31  14.2645  14.2645  14.2645  14.2645  14.26452007-12-31  15.6253  15.6253  15.6253  15.6253  15.62532008-12-31  35.8547  35.8547  35.8547  35.8547  35.85472009-12-31  22.6811  22.6811  22.6811  22.6811  22.68112010-12-31  18.3737  18.3737  18.3737  18.3737  18.37372011-12-31  32.2291  32.2291  32.2291  32.2291  32.22912012-12-31  29.7916  29.7916  29.7916  29.7916  29.79162013-12-31  23.6372  23.6372  23.6372  23.6372  23.63722014-12-31  19.6675  19.6675  19.6675  19.6675  19.66752015-12-31 -11.1408 -11.1408 -11.1408 -11.1408 -11.14082016-12-31   6.5580   6.5580   6.5580   6.5580   6.55802017-12-31  -4.9167  -4.9167  -4.9167  -4.9167  -4.91672018-12-31  16.7456  16.7456  16.7456  16.7456  16.74562019-12-31  21.2189  21.2189  21.2189  21.2189  21.2189
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python