Created
June 12, 2022 23:06
-
-
Save ajfriend/6942bdd4a9eb31861f7dfab471f411fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import duckdb | |
def dquery( | |
query_string, | |
_single_row_as_dict_=True, | |
**dfs_for_query, | |
): | |
con = duckdb.connect(database=':memory:') | |
for tbl_name, df in dfs_for_query.items(): | |
con.register(tbl_name, df) | |
out = con.execute(query_string).df() | |
if _single_row_as_dict_ and len(out) == 1: | |
out = dict(out.iloc[0]) | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://duckdb.org/2021/05/14/sql-on-pandas.html