2017-02-26 4 views
2

매월 원시 데이터를 나타내는 상자가있는 시간 지정 데이터의 상자 그림을 만들어야합니다. 이런 식으로 뭔가 : 이제팬더 DataFrame에서 월 단위로 행을 그룹화하려면 어떻게해야합니까?

enter image description here

은의 그 사용 팬더 만들려고하자 :

matplotlib inline 
import numpy as np 
import pandas as pd 

N_DAYS = 100 
dates = pd.date_range('20130101', periods=N_DAYS) 
df = pd.DataFrame(np.random.randn(N_DAYS,1), index=dates) 

나는 달 (코드 M)에 의해 재 샘플링 할 수 있습니다 및 집계 기능을 적용 같은 median 등 :

df.resample('M').median() 

그러나 데이터의 상자 그림을 만들 수 없습니다.

df.resample('M').boxplot(); 

이렇게하면 각 달의 평균 분포를 나타내는 상자 하나가 만들어집니다.

FutureWarning: 
.resample() is now a deferred operation 
You called boxplot(...) on this deferred object which materialized it into a dataframe 
by implicitly taking the mean. Use .resample(...).mean() instead 

이 어떻게 매월 원시 데이터의 상자 그림을 만들려면 어떻게해야합니까 :

enter image description here

또한, 나는 다음과 같은 경고를 얻을? 또한 docs을 확인할 수 있습니다

df['per'] = df.index.to_period('M') 
df.boxplot(by='per') 

graph

:

답변

3

당신이 그룹을 만들 수 by 키워드 인수를 사용하여 상자 그림 층화에 대한 period 첫번째 새로운 열을 생성해야 할 것 같다.

관련 문제