Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

seekwellpandas-0.1.7.tar.gz (49.6 kB view details)

Uploaded Source

Built Distribution

seekwellpandas-0.1.7-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file seekwellpandas-0.1.7.tar.gz.

File metadata

  • Download URL: seekwellpandas-0.1.7.tar.gz
  • Upload date:
  • Size: 49.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for seekwellpandas-0.1.7.tar.gz
Algorithm Hash digest
SHA256 88d898ee99c0c1efcb46d2c0f9c8fba55936432f2d8456ecf42b5eb480933f79
MD5 abd72d96a83bae07a8f4a0fc0e2f5791
BLAKE2b-256 429b8d25ad00511e4a87d1ffb66b942abd50c547f57f8b765ad4203c46a5ac6e

See more details on using hashes here.

File details

Details for the file seekwellpandas-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for seekwellpandas-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 178c93c9d981f4350843e67ab2d890613b76a100eaa452c5ab077ae4c6b6ff44
MD5 cc7d3725a34e027b2b3d5b6f5dccf2c2
BLAKE2b-256 fa1fe5b2ef4e0e5a16f45eca88c8780ff67e7d31d894d354f9bf2d84c130b27b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page