3.6 KiB
3.6 KiB
None
<html lang="en">
<head>
</head>
</html>
Writing to SQLite3+¶
The requirements to get started are minimal (actually none). The cell below creates a dataframe that will be stored within SQLite 3+
In [1]:
# # Writing to PostgreSQL database # import transport from transport import providers import pandas as pd _data = pd.DataFrame({"name":['James Bond','Steve Rogers','Steve Nyemba'],'age':[55,150,44]}) sqw = transport.factory.instance(provider=providers.SQLITE,database='/home/steve/demo.db3',table='friends',context='write') sqw.write(_data,if_exists='replace') #-- default is append print (transport.__version__)
2.0.0
Reading from SQLite3+¶
The cell below reads the data that has been written by the cell above and computes the average age within a PostreSQL (simple query).
- Basic read of the designated table (friends) created above
- Execute an aggregate SQL against the table
NOTE
It is possible to use transport.factory.instance or transport.instance they are the same. It allows the maintainers to know that we used a factory design pattern.
In [2]:
import transport from transport import providers pgr = transport.instance(provider=providers.SQLITE,database='/home/steve/demo.db3',table='friends') _df = pgr.read() _query = 'SELECT COUNT(*) _counts, AVG(age) from friends' _sdf = pgr.read(sql=_query) print (_df) print ('--------- STATISTICS ------------') print (_sdf)
name age 0 James Bond 55 1 Steve Rogers 150 2 Steve Nyemba 44 --------- STATISTICS ------------ _counts AVG(age) 0 3 83.0
The cell bellow show the content of an auth_file, in this case if the dataset/table in question is not to be shared then you can use auth_file with information associated with the parameters.
NOTE:
The auth_file is intended to be JSON formatted. This is an overkill for SQLite ;-)
In [5]:
{ "provider":"sqlite", "database":"/home/steve/demo.db3","table":"friends" }
In [ ]: