如果行超出指定的限制,我将删除DF的所有列中的行.
我的代码是:
XDF= pd.DataFrame(columns=['A','B'],data=[[-10,20],[2,8],[4,1],[3,-1]])
print(xdf)
xdf_params_limits = pd.DataFrame(columns=['A','B'],index=['min','max'],data=[[0,1],[5,30]])
print(xdf_params_limits)
xdf_flt = xdf.apply(lambda x: (x[col]>xdf_params_limits[col].loc['min'])&(x[col]<xdf_params_limits[col].loc['max']) for col in xdf.columns, axis=1)
XDF= xdf[xdf_flt]
A B
0 -10 20
1 2 8
2 4 1
3 3 -1
A B
min 0 1
max 5 30
预期yields
XDF=
A B
1 2 8
当前输出:
81 def ast_parse(self, source, filename='<unknown>', symbol='exec'):
82 """Parse code to an AST with the current compiler flags active.
83
84 Arguments are exactly the same as ast.parse (in the standard library),
85 and are passed to the built-in compile function."""
---> 86 return compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1)
SyntaxError: Generator expression must be parenthesized (2981748052.py, line 5)