我正在尝试在我的 jinja2
模板之一中使用 pandas 否定运算符 ~
,但我相信它与他们的 special operator 冲突。 ~
。
{% for row in df.loc[ ~(df['is_test_result_pass']) , : ].itertuples() %}
产生以下异常...
jinja2.exceptions.TemplateSyntaxError, unexpected '~'
我可以在 python 端执行该操作,并通过否定选择传递另一个变量,但是 ~ 运算符映射到我可以在模板中调用的等效方法名称是什么。
最佳答案
df = pd.DataFrame({'is_test_result_pass':[True, False, False, True]})
print (df['is_test_result_pass'])
0 True
1 False
2 False
3 True
Name: is_test_result_pass, dtype: bool
print (np.logical_not(df['is_test_result_pass']))
0 False
1 True
2 True
3 False
Name: is_test_result_pass, dtype: bool
关于python - pandas 否定运算符的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51733792/