2016-08-01 79 views
0

我是新來的數據分析人員,並且希望繪製一個具有多個日期列作爲座標軸的表格。我曾經嘗試這樣做:在一個座標軸上繪製多列python

years = [data['1996'],data['1997'],data['1998'],data['1999'],data['2000']] 
data.plot(x=years,y=data['City']) 

[data.plot(data[:,x],data2['City']) for x in range(3,5)] 
plot.show() 

,其中數據是大熊貓dataframer,無論是在工作。我覺得這可能很簡單,但似乎無法在任何地方找到解決方案。

感謝

回答

0

看起來需要set_indexCity柱,然後通過T和轉最後DataFrame.plot

import pandas as pd 
import matplotlib.pyplot as plt 


data = pd.DataFrame({'City':['a','b','c','d'], 
          '1996':[1,2,7,5], 
          '1997':[4,0,6,3], 
          '1998':[7,8,6,9], 
          '1999':[0,5,3,0]}) 

print (data) 
    1996 1997 1998 1999 City 
0  1  4  7  0 a 
1  2  0  8  5 b 
2  7  6  6  3 c 
3  5  3  9  0 d 

print (data.set_index('City').T) 
City a b c d 
1996 1 2 7 5 
1997 4 0 6 3 
1998 7 8 6 9 
1999 0 5 3 0 

data.set_index('City').T.plot() 
plt.show() 
相關問題