PyTables where方法中的条件表达式

2024-05-14 05:36:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在PyTables where方法中使用条件表达式。在SQL中,我将使用CASE表达式(PostgreSQL,“CASE WHEN a=b THAN 1 ELSE 0”),如果使用python,我将使用条件表达式“1 WHEN a==b ELSE 0”。但是我找不到如何在PyTableswhere方法中实现它。你知道吗

我查过http://pytables.github.io/usersguide/condition_syntax.html,但我不知道这是否可能。你知道吗


Tags: 方法githubhttpsql表达式postgresqlwhere条件
1条回答
网友
1楼 · 发布于 2024-05-14 05:36:49

您可以使用where(predicate, num1, num2)。你知道吗

table.where('where(a==b, 1, 0) == c')

根据Conditional Syntax

where(bool, number1, number2): number - number1 if the bool condition is true, number2 otherwise.

相关问题 更多 >