@@ -89,3 +89,42 @@ Insert Data
89
89
90
90
# create a random stream if not exist
91
91
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