値のデータフレームがあり、外れ値である行を調査したいと考えています。関数で呼び出すことができる以下のgroupby().apply()
関数を作成しました。これは、高い値または低い値に対してうまく機能しますが、それらを組み合わせたいときにエラーが発生します。どういうわけかブール選択を台無しにしていOR
ますが、を使用した選択基準のドキュメントしか見つけることができませんでし&
た。任意の提案をいただければ幸いです。
ザックcp
df = DataFrame( {'a': [1,1,1,2,2,2,2,2,2,2], 'b': [5,5,6,9,9,9,9,9,9,20] } )
#this works fine
def get_outliers(group):
x = mean(group.b)
y = std(group.b)
top_cutoff = x + 2*y
bottom_cutoff = x - 2*y
cutoffs = group[group.b > top_cutoff]
return cutoffs
#this will trigger an error
def get_all_ outliers(group):
x = mean(group.b)
y = std(group.b)
top_cutoff = x + 2*y
bottom_cutoff = x -2*y
cutoffs = group[(group.b > top_cutoff) or (group.b < top_cutoff)]
return cutoffs
#works fine
grouped1 = df.groupby(['a']).apply(get_outliers)
#triggers error
grouped2 = df.groupby(['a']).apply(get_all_outliers)