我有以下数据表:
df = pd.DataFrame({'Well': ['A', 'A', 'B', 'B'],
'BP': [380., 25., 24., 360.],
'ng': [1., 10., 1., 10.],
'Band A': [True, False, False, True],
'Band B': [False, True, True, False]})
字符串
我需要帮助创建一个sql查询,如果在“Well”中满足以下条件,则返回true:“Band A”为“True”,“Band A”的“ng”大于“Band B”的“ng”
我做了以下不成功的尝试,被卡住了:
sqlcmd = '''
SELECT
Well,
ng,
CASE
WHEN Band_A = True AND ng > (SELECT ng FROM df WHERE Band_B = True) THEN 'True'
ELSE 'False'
END AS Duplicate
FROM df
ORDER BY Well;'''
pp.pprint(pysqldf(sqlcmd).head())
型
1条答案
按热度按时间bfhwhh0e1#
我跳过Pandas并演示如何在纯SQLite中完成此操作。它应该是可翻译的。
个字符