I have the following data table:
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]})
I need help creating an sql query that returns true if, within "Well", the following conditions are met: "Band A" is "True" and "ng" for "Band A" is greater than "ng" for "Band B"
I made the following unsuccessful attempt, and am stuck:
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())
I skip Pandas and demonstrate how to do this in pure SQLite. It should be translatable.