2016-12-30 1 views
2

플롯에 데이터 프레임의 일부로 주석을 추가하려고합니다. 그러나 00:00:00 시간이 모든 행 레이블에 나타납니다. 내 데이터가 매일 빈번히 발생하기 때문에이를 제거 할 수있는 깨끗한 방법이 있습니까? normalize 함수를 시도했지만 시간을 제거하지는 못합니다. 그것은 단지 시간을 제로.플롯에서 팬더 테이블의 인덱스 포맷하기

다음은 문제의 모양과 문제를 재현하는 샘플 코드입니다.

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
from pandas.tools.plotting import table 

# Setup of mock data 
date_range = pd.date_range('2014-01-01', '2015-01-01', freq='MS') 
df = pd.DataFrame({'Values': np.random.rand(0, 10, len(date_range))}, index=date_range) 

# The plotting of the table 
fig7 = plt.figure() 
ax10 = plt.subplot2grid((1, 1), (0, 0)) 
table(ax10, np.round(df.tail(5), 2), loc='center', colWidths=[0.1] * 2) 
fig7.show() 

답변

1

enter image description here은 단순히 인덱스의 모든 개별 요소가 datetime.date 형식으로 표현 될 것이다 그래서 DateTimeIndex.date 속성에 액세스 할 수 있습니다.

기본값 인 DateTimeIndexdatetime.datetime이며, 이전에 명시 적으로 색인을 정의하지 않았더라도 자동으로 정의됩니다.

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
from pandas.tools.plotting import table 

np.random.seed(42) 
# Setup of mock data 
date_range = pd.date_range('2014-01-01', '2015-01-01', freq='MS') 
df = pd.DataFrame({'Values': np.random.rand(len(date_range))}, date_range) 
df.index = df.index.date         # <------ only change here 

# The plotting of the table 
fig7 = plt.figure() 
ax10 = plt.subplot2grid((1, 1), (0, 0)) 
table(ax10, np.round(df.tail(5), 2), loc='center', colWidths=[0.1] * 2) 
fig7.show() 

enter image description here