New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pandaq

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pandaq

An easy pandas query-string builder.

  • 0.1.0
  • PyPI
  • Socket score

Maintainers
1

pandaq: An easy pandas query-string builder

test codecov PyPI - Version PyPI - Python Version

This library provides q method for easy querying of pandas.DataFrame. Internally, q generates the query string for pandas.DataFrame.query.

The goal of pandaq is to save time when querying.

Installation

pip install pandaq

Usage

pandaq provides two ways to select pandas.DataFrame rows by query string.

A. Generate a query-string
from pandaq import Q
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv')
qstr = Q().q(PassengerId=1)  # -> "PassengerId==1"
df.query(qstr)
B. Add q method to pandas.DataFrame
import pandaq.patch
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv')
df.q(PassengerId=1)

How to construct a query

Basics

Query TypeHow It Works
q("str")Equivalent to pd.DataFrame.query("str")
q(dict)Works like q(**dict)
q(k=v)Where the column named k is equal to v
q(k=[v1, ...])Where the column named k is in [v1, ...]
q(k=(op1, v1, ...))Where the column named k meets the condition k op1 v1 and ...
q(k="!str")Where the column named k is NOT str (see Advance)
q(k="?str")Where the column named k contains str (see Advance)
q(k="!?str")Where the column named k does NOT contain str (see Advance)
q(k="/str")Where the column named k match the regex str (see Advance)
Example
TypeKindpandaq.qEquivalent to query-string
NumberEqualq(a=1)"a==1"
NumberContainq(a=[1, 2])"a==1 or a==2"
NumberInequalityq(a=(">", 1))"a>1"
NumberInequalityq(a=(">", 1, "<=", 3))"a>1 and a<=3"
BoolEqualq(a=True)"a==True"
StrFull-Matchq(a="text")'a=="text"'
StrNot Full-Matchq(a="!text")'a!="text"'
StrPartial-Matchq(a="?text")'a.str.contains("text", regex=False, na=False)'
StrNot Partial-Matchq(a="!?text")'not a.str.contains("text", regex=False, na=False)'
StrRegex-Matchq(a="/textA|textB")'a.str.contains("textA|textB", regex=True, na=False)'
DatetimeEqualq(a=dt.date(1970,1,1))'a=="1970-01-01"'
DatetimeInequalityq(a=(">", dt.date(1970,1,1)))'a>"1970-01-01"'

Combination

pandaq.qEquivalent to query-string
q(a=1, b=1)"(a==1 & b==1)"
q(a=1).q(b=1)"a==1 & b==1"

Advanced Usage

To set the prefix individually, configure the following settings.

from pandaq import config

# Default settings
config.str_prefix = StringPrefix(
    neq="!",  # The prefix for not equal
    regex="/",  # The prefix for regular expressions
    partial="?",  # The prefix for partial match
    neq_partial="!?",  # The prefix for not equal partial match
)

License

pandaq is distributed under the terms of the MIT license.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc