しきい値に基づいてシリーズからデータを選択しています。
>>> s = pd.Series(np.random.randn(5))
>>> s
0 -0.308855
1 -0.031073
2 0.872700
3 -0.547615
4 0.633501
dtype: float64
>>> cfg = {'threshold' : 0 , 'op' : 'less' }
>>> ops = {'less' : '<', 'more': '>' , 'equal': '==' , 'not equal' : '!='}
>>> ops[cfg['op']]
'<'
>>> s[s < cfg['threshold']]
0 -0.308855
1 -0.031073
3 -0.547615
dtype: float64
「<」の代わりに、コードの最後の行で ops[cfg['op']] を使用したい。必要に応じて ops dict の key 、値を変更します (< の代わりに -lt のように)。これはどのように行うことができますか?