I would like to filter rows by a function of each row, e.g.
def f(row):
return sin(row[\'velocity\'])/np.prod([\'masses\']) > 5
df = pandas.DataFrame(.
The best approach I've found is, instead of using reduce=True to avoid errors for empty df (since this arg is deprecated anyway), just check that df size > 0 before applying the filter:
def my_filter(row):
if row.columnA == something:
return True
return False
if len(df.index) > 0:
df[df.apply(my_filter, axis=1)]