2017-01-06 3 views
2
import sys 
import ConfigParser 
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.dates as mdates 
import datetime as DT 
import bokeh 
sys.path.extend(['..\..\myProj\SOURCE']) 

fullfilepath = "../../myProj/SOURCE/" + 'myparts.txt' 
ohg_df = pd.read_csv(fullfilepath, sep="\t") 

temp_df = temp_df[['as_on_date', 'ohg_qty']] 

temp_df = temp_df.sort(['as_on_date'], ascending=[1]) 

temp_df.set_index('as_on_date') 

plt.plot(temp_df.index, temp_df.ohg_qty) 

plt.show() 

가져온 후 내 데이터 프레임입니다.matplotlib 데이터 프레임 x 축 날짜 문제

x axis과 함께 꺾은 선형 그래프를 데이터 프레임에 언급 된 날짜로 플롯하려고합니다.

누군가 나를 인도 할 수 있습니까? 나는 팬더를 처음 사용합니다.

dataframe picture

output pitcure

+0

무슨 문제가 있나요? '목성 노트 '나 똑같은 것을 사용합니까? –

+0

'temp_df = temp_df.set_index ('as_on_date')'또는'temp_df.set_index ('as_on_date', inplace = True)'을 써라. –

+0

그래 .. .. jupyter를 사용하고 .. 플롯에서 dateson이 x- 축 ... 인덱스 번호를 얻고있다 – Santor

답변

0

쉽게 :

# Set index directly 
ohg_df = pd.read_csv(fullfilepath, sep="\t", index='as_on_date') 

# Convert string index to dates 
ohg_df.index = pd.to_datetime(ohg_df.index) 

# Get a column and plot it (taking a column keeps the index) 
plt.plot(ohg_df.ohg_qty) 
+0

인덱스로 as_on_date를 만든 후에도 x 축에 날짜가 표시되지 않습니다 .... x 축을 100000, 200000, 300000으로 가져 오는 중 – Santor

+0

질문에 outputpicture를 추가했습니다. , – Santor

+0

질문의 하단에 출력 그림을 추가했습니다. – Santor