【发布时间】:2013-10-11 22:33:17
【问题描述】:
我有一组数据,我使用 pandas 数据框加载到 python 中。我想做的是创建一个循环,该循环将为它们自己的框架中的所有元素打印一个图,而不是全部在一个上。我的数据以这种方式存储在一个 excel 文件中:
Index | DATE | AMB CO 1 | AMB CO 2 |...|AMB CO_n | TOTAL
1 | 1/1/12| 14 | 33 |...| 236 | 1600
. | ... | ... | ... |...| ... | ...
. | ... | ... | ... |...| ... | ...
. | ... | ... | ... |...| ... | ...
n
这是我目前所拥有的代码:
import pandas as pd
import matplotlib.pyplot as plt
ambdf = pd.read_excel('Ambulance.xlsx',
sheetname='Sheet2', index_col=0, na_values=['NA'])
print type(ambdf)
print ambdf
print ambdf['EAS']
amb_plot = plt.plot(ambdf['EAS'], linewidth=2)
plt.title('EAS Ambulance Numbers')
plt.xlabel('Month')
plt.ylabel('Count of Deliveries')
print amb_plot
for i in ambdf:
print plt.plot(ambdf[i], linewidth = 2)
我正在考虑做这样的事情:
for i in ambdf:
ambdf_plot = plt.plot(ambdf, linewidth = 2)
以上内容并不是我想要的,它源于我对 Pandas、MatplotLib 等的不熟悉,查看了一些文档,但在我看来,甚至不需要 matplotlib(问题 2)
所以 A)如何为我的 df 中的每一列生成数据图 B)我需要使用 matplotlib 还是应该只使用 pandas 来完成这一切?
谢谢,
【问题讨论】:
-
您可以为每一列的绘图添加额外的系列,或者为每列创建一个单独的绘图。我猜你更喜欢后者?此外,
matplotlib是一个非常标准的绘图模块,非常易于使用,并且工作起来就像做梦一样。 -
真的没关系,这只是为了让我使用它并练习它,惯例会规定一种方法而不是另一种方法吗?
标签: python-2.7 matplotlib pandas