Tidyverse-style string ops in Python.
Project description
Tidy(Py)String: Wrangle those Strings
Easier string operations in Python, inspired by the tidyverse (especially stringr).
All functions can be run both on single strings and vectors of strings, with direct support for base python's string type (str), lists or arrays of strings ([str, str, ...]), and Pandas columns / series (pd.Series), and indirect support other string-like or string-typed variables.
Quick Start
Install the package from PyPI:
pip install tidystring
Requirements:
- Python 3.9 or higher
- pandas 1.2.4 or higher
Then, wrangle those strings:
import pandas as pd
import tidystring as ts
strings = pd.Series(["text_alpha", "text_beta", "text_gamma"])
## detect if strings contain "alpha"
ts.str_detect(strings, "alpha")
## remove "alpha" from all strings
ts.str_remove(strings, "alpha")
## convert all strings to title case, removing dashes
ts.str_to_title(strings, remove_dashes=True)
Inspired by StringR
... which offers the following functions:
str_length()str_sub()str_dup()str_trim()str_pad()str_wrap()str_to_upper()str_to_lower()str_to_title()str_detect()str_count()str_locate()str_locate_all()str_extract()str_extract_all()str_match()str_match_all()str_replace()str_replace_all()str_split()str_split_fixed()str_glue()str_order()str_sort()str_subset()str_which()str_squish()str_flatten()
(All of these are on my to-do list, but for now...)
tidystring's currently available stringr ports:
str_detect()str_remove()str_extract()str_split()str_trim()str_to_title()str_to_upper()str_to_lower()
Additional tidystring functions not in stringr:
str_concatstr_startswithstr_endswithstr_upper_cutstr_search_applystr_search_recasestr_dash_to_space
Check out the documentation for more information.
Tidyverse-Inspired Python
There are increasingly a number of other Python packages that are helping to bring the beautiful tidyverse to Python. Here's a couple to consider:
Here's a short-list of some stand-outs:
Development Notes
Installation Options
Install the stable version from PyPI:
pip install tidystring
Or install the latest development version from GitHub:
pip install git+https://github.com/ColinConwell/TidyPyString.git
Code Formatting
If you're contributing to the project, you can use the provided formatting scripts:
# Format the code (modifies files)
./devops/run_format.sh
# Check code formatting (doesn't modify files)
./devops/run_linter.sh
Use of Generative AI
All code in this package has been tested by me (a human), but much of the documentation comes from a custom generative AI auto-documentation pipeline, powered by Claude-Sonnet-3.7. Documentation may thus be subject to some error. Please feel free to file an issue if this appears to be the case.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tidystring-0.1.0.tar.gz.
File metadata
- Download URL: tidystring-0.1.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.21 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89f154c3b84f0376cda649b348645a4febce1d4002baa1ae06d77e00a7a5b30f
|
|
| MD5 |
edf175a4261a36b2dc5e482808a474a9
|
|
| BLAKE2b-256 |
d8d6f2a618b42acd7b0cb653641a28d668589bda337c6d44890653d1cf58c084
|
File details
Details for the file tidystring-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tidystring-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.21 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7bde3830fd0974be59bfde70fc4c2acf8eda2e286e9786ae48c87f1c7b4e99b
|
|
| MD5 |
d8fb1d1c6551741f43a588ba77da0014
|
|
| BLAKE2b-256 |
bedd36aa0e60e0a0522327c54a06c6b4187ac60dbdc991c833e14cd5f16b73bc
|