我想通过每行的函数过滤行,例如
def f(row):
return sin(row['velocity'])/np.prod(['masses']) > 5
df = pandas.DataFrame(...)
filtered = df[apply_to_all_rows(df, f)]
或者对于另一个更复杂、人为的例子,
def g(row):
if row['col1'].method1() == 1:
val = row['col1'].method2() / row['col1'].method3(row['col3'], row['col4'])
else:
val = row['col2'].method5(row['col6'])
return np.sin(val)
df = pandas.DataFrame(...)
filtered = df[apply_to_all_rows(df, g)]
我该怎么做?