2017-03-24 4 views
1

을 만들 나는 dataframe팬더 : 플롯

  bank_card used_at unique_users all_time 
0   Credit 2015-01   513 2368.0 
1   Credit 2015-02   352 1375.0 
2   mortgage 2015-01   355 1235.0 
3   mortgage 2015-02   394 2147.0 
4   mortgage 2015-03   298 1401.0 
5   mortgage 2015-04   350 1890.0 

하고 난 그래프를 생성 할 필요가있다. 나는 그것을하려고 노력하고 얻으려고한다 graph 나는 축 xused_at 값을 얻을 필요가있다. all_time 모든 유형의 축 bank_card.

축의 이름 만 설정합니다. ax.set_xlabel("used_at", fontsize=12) 어떻게 할 수 있습니까?

답변

1

당신은 'used_at'

idf = df.set_index('used_at') 

결과에 인덱스를 설정하여이 작업을 수행 할 수 있습니다

>>> idf.plot(y='all_time') 
<matplotlib.axes._subplots.AxesSubplot object at 0x0000000011D0FDA0> 
>>> plt.show() 

enter image description here

편집 : 당신은 당신이 가서 여기에 하나의 플롯에 신용과 모기지 모두를 원하는 :

>>> idf.groupby('bank_card')['all_time'].plot() 
bank_card 
Credit  Axes(0.125,0.1;0.775x0.8) 
mortgage Axes(0.125,0.1;0.775x0.8) 
Name: all_time, dtype: object 
>>> plt.legend(loc='best') 
<matplotlib.legend.Legend object at 0x0000000011924588> 
>>> plt.show() 

결과 :

enter image description here

+0

하지만 어떻게 하나의 플롯에'Credit'와'mortgage' 2 개 곡선을 얻을 수 있나요? –

+0

@ PetroPetrov : 편집 된 답변을 참조하십시오. – bernie

+0

감사합니다! 그것은 맘에 드는 입력 –