pandas 数据框图 [英] Pandas Data Frame Plotting
本文介绍了 pandas 数据框图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个Pandas DataFrame
I have this Pandas DataFrame
这给了我这个
我怎么
- 树立新形象
- 将标题添加到此处标题"图中
- 以某种方式创建映射,以使标签不是"29,30"等,而是说"29周","30周"等.
- 将图表的较大版本(例如10 x 10英寸)保存到我的计算机中
我已经一个多小时困惑这个问题了!
I have been puzzling over this for an hour now!
推荐答案
You can use the rename
DataFrame method:
In [1]: df = pd.DataFrame(np.random.randn(7, 5),
index=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
columns=[29, 30, 31, 32, 33])
In [2]: df
Out[2]:
29 30 31 32 33
Mon -0.080946 -0.072797 -1.019406 1.149162 2.727502
Tue 1.041598 -0.730701 -0.079450 1.323332 -0.823343
Wed 0.338998 1.034372 -0.273139 0.457153 0.007429
Thu -2.239857 -0.439499 0.675963 0.966994 1.348100
Fri 0.050717 -0.506382 1.269897 -0.862577 1.205110
Sat -1.380323 0.200088 -0.685536 -0.425614 0.148111
Sun -0.248540 -1.056943 1.550433 0.651707 -0.041801
In [3]: df.rename(columns=lambda x: 'Week ' + str(x), inplace=True)
In [5]: df
Out[5]:
Week 29 Week 30 Week 31 Week 32 Week 33
Mon -0.080946 -0.072797 -1.019406 1.149162 2.727502
Tue 1.041598 -0.730701 -0.079450 1.323332 -0.823343
Wed 0.338998 1.034372 -0.273139 0.457153 0.007429
Thu -2.239857 -0.439499 0.675963 0.966994 1.348100
Fri 0.050717 -0.506382 1.269897 -0.862577 1.205110
Sat -1.380323 0.200088 -0.685536 -0.425614 0.148111
Sun -0.248540 -1.056943 1.550433 0.651707 -0.041801
然后您可以用标题绘制它:
You can then plot this with a title:
In [4]: df.plot(title='Title Here')
在文档的可视化部分中查看更多信息.
See more in the visualisation section of the docs.
注意: 查看全文