Skip to content

Commit 6c83c35

Browse files
authored
Update README.rst, adding pandas example
1 parent a98903d commit 6c83c35

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,42 @@ Insert Data
8989
9090
# create a random stream if not exist
9191
c.execute("INSERT INTO proton_stream (raw) VALUES",rows) #rows is an array of arrays
92+
93+
Pandas DataFrame
94+
----------------
95+
Big fan of Pandas? We too! You can mix SQL and Pandas API together:
96+
97+
.. code-block:: python
98+
99+
import pandas as pd
100+
import time
101+
102+
from proton_driver import client
103+
104+
if __name__ == "__main__":
105+
c = client.Client(host='127.0.0.1', port=8463)
106+
107+
# setup the test stream
108+
c.execute("drop stream if exists test")
109+
c.execute("""create stream test (
110+
year int16,
111+
first_name string
112+
)""")
113+
# add some data
114+
df = pd.DataFrame.from_records([
115+
{'year': 1994, 'first_name': 'Vova'},
116+
{'year': 1995, 'first_name': 'Anja'},
117+
{'year': 1996, 'first_name': 'Vasja'},
118+
{'year': 1997, 'first_name': 'Petja'},
119+
])
120+
c.insert_dataframe(
121+
'INSERT INTO "test" (year, first_name) VALUES',
122+
df,
123+
settings=dict(use_numpy=True),
124+
)
125+
# or c.execute("INSERT INTO test(year, first_name) VALUES", df.to_dict('records'))
126+
time.sleep(3) # wait for 3 sec to make sure data available in historical store
127+
128+
df = c.query_dataframe('SELECT * FROM table(test)')
129+
print(df)
130+
print(df.describe())

0 commit comments

Comments
 (0)