Skip to content

Commit

Permalink
Update DataFrame expamle (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yibo-Chen13 authored Nov 5, 2024
1 parent c19c0e0 commit 2e6331e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions example/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@
print(df)
print(df.describe())

# Also you can use proton settings in DataFrame API like using `execute` function. # noqa
# Here's an example with idempotent id.

# Reset stream
c.execute('drop stream if exists test')
c.execute(
"""create stream test (
year int16,
first_name string
)"""
)
settings = dict(use_numpy=True, idempotent_id='batch')

# Execute multiple insert operations.
for _ in range(5):
c.insert_dataframe(
'INSERT INTO "test" (year, first_name) VALUES',
df,
settings=settings,
)
time.sleep(3)

rv = c.execute('SELECT COUNT(*) FROM table(test)')
# Only the first times insert into the historical storage.
print(rv) # (4,)

# Converting query results to a variety of formats with dbapi
with connect('proton://localhost') as conn:
with conn.cursor() as cur:
Expand Down

0 comments on commit 2e6331e

Please sign in to comment.