Skip to content

Instantly share code, notes, and snippets.

@ajfriend
Created June 12, 2022 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajfriend/6942bdd4a9eb31861f7dfab471f411fb to your computer and use it in GitHub Desktop.
Save ajfriend/6942bdd4a9eb31861f7dfab471f411fb to your computer and use it in GitHub Desktop.
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
@ajfriend
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment