0
私はオブジェクト型のパンダデータフレームを持っています。Python:np.nanpercentile、データフレームにはどのデータ型が必要ですか?
df.dtypes
Out:
data object
stimulus object
trial object
dtype: object
df.head()
Out:
data stimulus trial
0 2 -2 1
1 2 -2 2
2 2 -2 3
3 2 -2 4
4 2 -2 5
私のデータセットの特定のパーセンタイルを取得したいとします。このコードを使用すると、おそらく私のデータセット自体にNaNがあり、Pythonが無限大として解釈するので、より高いパーセンタイルを計算するときに問題が発生するため、出力にNaNを取得します。 (私はすでに代わりに)私は(np.nanpercentileを使用する必要があるということが分かったが、私はnp.nanpercentile使用する場合
df.groupby('stimulus').data.apply(lambda x: np.percentile(x, q=66))
Out:
stimulus
-2.00 2.0
-1.75 2.9
-1.00 1.0
-0.75 1.0
-0.50 0.0
0.50 7.8
1.00 9.9
1.25 11.9
1.75 13.9
2.50 NaN
)の代わりに、私はこのエラーを取得します。 np.nanpercentile()が入力配列のデータ形式をチェックし、それが適合しない場合に文句を言うところを読んでいます。どのようにデータを変更する必要があるのか、どのフォーマットになっているのか分かりますか?
df.groupby('stimulus').data.apply(lambda x: np.nanpercentile(x, q=66))
Out:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
は、あなただけのnumpyの配列にデータを変換し、それにnp.nanpercentile適用することはできますか? Arr = df.as_matrix(column_number)と同様に、np.nanpercentile(Arr、66) – jfish003