API: chained reshaping ops · Issue #11485 · pandas-dev/pandas (original) (raw)

accept callables

In [4]: df = DataFrame({'A' : [1,2,3,4], 'B' : ['a',np.nan,'b','a']})

In [5]: df
Out[5]: 
   A    B
0  1    a
1  2  NaN
2  3    b
3  4    a

an operation that changes the shape of the DataFrame

In [9]: res = df.dropna()

In [10]: res[res.B=='a']
Out[10]: 
   A  B
0  1  a
3  4  a

can be done like this

In [8]: df.dropna().pipe(lambda x: x[x.B=='a'])
Out[8]: 
   A  B
0  1  a
3  4  a

SQL calls this select, which pandas has, but both select/filter are used for filtering LABELS (and not data).

I suppose making this work:

df.dropna().loc[lambda x: x[x.B=='a']] is maybe a slight enhancement of this

any thoughts?