我有一組數據,我使用熊貓數據框加載到python中。我想要做的是創建一個循環,它將爲自己的框架中的所有元素打印一個情節,而不是一個一個。我的數據是在以這種方式構建Excel文件:使用循環繪製n個圖表Python
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或者我應該只使用熊貓來完成這一切?
謝謝
你可能只是額外的系列地繪製每一列的繪圖或爲每一列創建一個單獨的繪圖。我猜你喜歡後者?另外,'matplotlib'是製作情節的一個非常標準的模塊,非常容易使用,並且像夢一樣運作。 –
這真的沒關係,這只是讓我使用它並且實踐它,會議是否規定了一種方法? –