SQL queries on Pandas data frames
Project description
Seek well, pandas
seekwellpandas
(SQL-pandas) is a pandas extension that provides SQL-inspired methods to manipulate DataFrames in a more intuitive way, closely resembling SQL syntax.
Features
seekwellpandas
adds the following methods to your pandas DataFrames:
select()
: Select specific columns, including negative selection.where_()
: Filter rows based on a condition.group_by()
: Group data by one or more columns.having()
: Filter groups based on a condition.order_by()
: Sort data by one or more columns.limit()
: Limit the number of returned rows.join_()
: Join two DataFrames.union()
: Union two DataFrames.distinct()
: Remove duplicates.intersect()
: Find the intersection between two DataFrames.difference()
: Find the difference between two DataFrames.with_column()
: Add a new column based on an expression.rename_column()
: Rename a column.cast()
: Change the data type of a column.drop_column()
: Remove one or more columns.unpivot()
: Transform columns into rows (melt).group_having()
: Combine grouping and group filtering.
Installation
You can install seekwellpandas
via pip:
pip install seekwellpandas
Usage
Here are some examples of how to use SeekwellPandas:
import pandas as pd
import seekwellpandas
# Create a sample DataFrame
df = pd.DataFrame({
'A': [1, 2, 3, 4],
'B': ['a', 'b', 'a', 'b'],
'C': [10, 20, 30, 40]
})
# Select columns
result = df.select('A', 'B')
# Negative selection
result = df.select(-'A')
# Filter rows redirecting to .query() (the _ avoids overlapping with pandas.DataFrame.where)
result = df.where_('A > 2')
# Group and aggregate
result = df.group_by('B').agg({'A': 'mean', 'C': 'sum'})
# Sort data
result = df.order_by('C', ascending=False)
# Add a new column
result = df.with_column('D', 'A * C')
# Join two DataFrames (the _ avoids overlapping with pandas.DataFrame.join)
df2 = pd.DataFrame({'B': ['a', 'b'], 'D': [100, 200]})
result = df.join_(df2, on='B')
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request on my GitHub repository.
License
This project is licensed under the GPLv3 License. See the LICENSE file for details.
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 seekwellpandas-0.1.8.tar.gz
.
File metadata
- Download URL: seekwellpandas-0.1.8.tar.gz
- Upload date:
- Size: 49.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0960eaa99772128030ca4ed8455443090c7a6bb62dd750163a55fe2f4fa1df8f |
|
MD5 | 5d292728f678f51641f7629755747855 |
|
BLAKE2b-256 | 55a6ca9c687dbe18a0ea7fa51716e3cd7fc90a9fb0a3590d9f40dba75b22a6ed |
File details
Details for the file seekwellpandas-0.1.8-py3-none-any.whl
.
File metadata
- Download URL: seekwellpandas-0.1.8-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5263810f416cdc724ae8b5bbe7b29f3e7bfa2b7095bff380ba21657d181d7563 |
|
MD5 | 38fb20960535ea3cd6b121df72407227 |
|
BLAKE2b-256 | ee192b97260324f878d9c04f7a717ba17b5552da41e2c6ee23e4ecfb4d1ff79c |