Pandas-ORM Integration.
Project description
RedPanda: Pandas & SQLAlchemy
Two great tastes that taste great together.
Use RedPanda to add simple pandas integration into your declarative models.
Installation
pip install redpanda
Basic Use
Create a session from a SQLAlchemy engine:
import redpanda
engine = redpanda.create_engine("sqlite://")
# => Engine(sqlite://)
Session = redpanda.orm.sessionmaker(bind=engine)
session = Session()
# => <sqlalchemy.orm.session.Session>
Querying
Use the frame()
method of RedPanda queries to return a DataFrame representation of the results instead of a collection of models.
query = session.query(MyModel)
# => <redpanda.orm.Query>
query.frame()
# => <pandas.DataFrame>
Querying with Filters
The frame()
method that wraps the pandas.read_sql()
function into a dialect-agnostic class-method for declarative SQLAlchemy models and can accept the same keyword arguments as pandas.read_sql()
:
query = session.query(MyModel).filter_by(my_attr="my_val")
query.frame(index_col="time")
Additionally, a within()
method is added to SQLAlchemy's InstrumentedAttribute class that accepts a pandas Index object:
index = pandas.period_range("2016-11-01", "2016-11-30", freq="W")
query = session.query(MyModel).filter(MyModel.timestamp.within(index))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file redpanda-0.6.0.tar.gz
.
File metadata
- Download URL: redpanda-0.6.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0d4351cebd2213e1907c19abb2dd2b1fafe092920142e9978238040f72c9576 |
|
MD5 | 43ff96ec9cfef7ebcdd6f47897f820e8 |
|
BLAKE2b-256 | c42d8765b12ce9d3b840b405554ed6fca5253392410d9ae006bbf40f6878bf46 |
File details
Details for the file redpanda-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: redpanda-0.6.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d6fdbe9158b4a4d6b570242d73687b8c889255b18e53e192dfe44189d74d629 |
|
MD5 | b4267dd50beb0620da85b2a5ff9db9fb |
|
BLAKE2b-256 | 125c831245e4d337dc5d10557a6d65fbd69e465dd221d3b4bb5d861e3978af64 |