How to access single cell value in Daft way? #3979
Answered
by
universalmind303
hongbo-miao
asked this question in
Q&A
-
I have a table. event_name = "abc"
conn_str = "trino://[email protected]/?source=trino-sqlalchemy"
sql_query = f"""
select cast(id as varchar) as id
from postgresql.public.my_events
where name = '{event_name}'
"""
event_df = daft.read_sql(sql_query, conn_str)
collected_df = event_df.collect()
id = collected_df.to_pandas().iloc[0]["id"] You can see I get string |
Beta Was this translation helpful? Give feedback.
Answered by
universalmind303
Mar 17, 2025
Replies: 1 comment
-
I think the most efficient way would be to use df = daft.from_pydict({"id": [1,2,3]});
df.to_arrow()["id"][1].as_py() # 2 you can also use df.to_pydict()['id'][1] # 2
df.to_pylist()[1]['id'] # 2 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hongbo-miao
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the most efficient way would be to use
to_arrow
and extract the cell that wayyou can also use
to_pydict
orto_pylist
depending on if you want columnar (pydict) or row (pylist).pydict
will be faster as it's closer to our in memory representation