2017-02-26 12 views
2

タイムデータのボックスプロットを作成する必要があり、毎月の生データを表すボックスがあります。このような何か:pandas 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(); 

これは、各月の平均の分布を表す1つのボックスを作成します。

enter image description here

また、私は次の警告を得る:

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 

をどのように私は、各月の生データの箱ひげ図を作成するのですか?

答えて

3

あなたがグループを作成するbyキーワード引数を使用して成層箱ひげ図のための最初のperiodのための新しい列を作成する必要があるようだ:

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

graph

あなたはまたdocsを確認することができます。

関連する問題