これを自分のデータで機能させることができないため、最初に非常によく似た具体的な例を試しています。データフレームは次のとおりです。
In [56]:
idx = pd.DatetimeIndex(start='1990-01-01', freq='d', periods=5)
data= pd.DataFrame({('A','a'):[1,2,3,4,5],
('A','b'):[6,7,8,9,1],
('B','a'):[2,3,4,5,6],
('B','b'):[7,8,9,1,2]}, idx)
Out[56]:
A B
a b a b
1990-01-01 1 6 2 7
1990-01-02 2 7 3 8
1990-01-03 3 8 4 9
1990-01-04 4 9 5 1
1990-01-05 5 1 6 2
したがって、私が望んでいるのは、各観測値 (インデックスの各日) の変数 (各列) の中心傾向の線で時系列をプロットし、指定された誤差推定量 (おそらくちょうど 95各日に対応する観察の % ci)。
私はこれを試しました:
sns.tsplot(data, time=idx)
しかし、次のエラーが表示されます。
UnboundLocalError Traceback (most recent call last)
<ipython-input-57-fa07e08ead95> in <module>()
5 ('B','b'):[7,8,9,1,2]}, idx)
6
----> 7 sns.tsplot(data, time=idx)
C:\Users\Patrick\Anaconda\lib\site-packages\seaborn\timeseries.pyc in tsplot(data, time, unit, condition, value, err_style, ci, interpolate, color, estimator, n_boot, err_palette, err_kws, legend, ax, **kwargs)
253
254 # Pad the sides of the plot only when not interpolating
--> 255 ax.set_xlim(x.min(), x.max())
256 x_diff = x[1] - x[0]
257 if not interpolate:
UnboundLocalError: local variable 'x' referenced before assignment
tsplot の構文は次のとおりです。
sns.tsplot(data, time=None, unit=None, condition=None, value=None, err_style='ci_band', ci=68, interpolate=True, color=None, estimator=<function mean at 0x00000000044F2C18>, n_boot=5000, err_palette=None, err_kws=None, legend=True, ax=None, **kwargs)
したがって、時間引数としてインデックスを使用してデータを提供していますが、何が間違っているのかわかりません。他のキーワード引数は必要ないと思いますが、それが問題かもしれません。
代わりに次元(単位、時間)の配列でこれを行うと:
sns.tsplot(data.values.T, time=idx)
期待される出力が得られます (タイムスタンプがない場合は xlabels です):
しかし、データフレームでこれを行う正しい方法は何ですか? 「長い形式」でなければならないことはわかっていますが、この特定のフレームでこれが何を意味するのかはよくわかりません。