Comments (12)
So they’re kind-of different things. I think this answer gives a better description of the differences than I could write here:
https://askubuntu.com/questions/714503/regular-expressions-vs-filename-globbing
In general, when searching for things I find globbing more useful (cause you just need an asterisk) but for validation regex is better because one can be more precise with what is expected.
from pyjanitor.
The above looks good, except “exact” is unnecessary. Regex or glob without wildcards will be equivalent.
from pyjanitor.
Needs a column_name / col_name (?), right?
Thank you. Updating...
from pyjanitor.
Also think that maybe col_name
should come before find
and replace
in the args list... From the at-a-glance understanding perspective, maybe df.do_this(to_this, with_this_particularly)
is more in line with what we have done with other functions.
from pyjanitor.
@zbarry good point! Updated the function signature.
from pyjanitor.
Should it support regular expressions?
🤔
from pyjanitor.
Regex is ok.... but globbing is nicer:
https://docs.python.org/3.6/library/fnmatch.html
from pyjanitor.
@zbarry I see you're saturated with relatives!
I think it's possible to support multiple ways of find and replace:
def find_replace(df, find, replace, kind='exact'):
kinds=['exact', 'regex', 'glob']
if kind not in kinds:
raise ValueError(f'kind kwarg has to be one of {kinds}')
if kind == 'exact':
# implementation goes here
if kind == 'regex':
# implementation goes here
if kind == 'glob':
# implementation goes here
return df
What do you all think?
from pyjanitor.
Ok, got it! Pardon my ignorance here, but is globbing a "subset" of regexing, or there mutually exclusive parts to them?
from pyjanitor.
Yeah 90% of the time I just use globbing. I only use regex when I absolutely have to. No idea how often you would need them in pandas-style applications.
from pyjanitor.
Ok! Synthesizing the discussion thus far:
def find_replace(df, col_name, find, replace, kind='glob'):
"""
# docstring opener above
Whether or not you use kind="glob" or "regex", if you do not use any wildcards,
it will default to an exact match. We expect an 80/20 split between exact/wildcard
usage, and with globbing being more easily understood than regexes, it is hence
the default choice.
# continue docstring below
"""
kinds=['regex', 'glob']
if kind not in kinds:
raise ValueError(f'kind kwarg has to be one of {kinds}')
if kind == 'regex':
# implementation goes here
else:
# implementation goes here
return df
Comments?
from pyjanitor.
Needs a column_name
/ col_name
(?), right?
from pyjanitor.
Related Issues (20)
- [INFRA] Switch over to pyproject.toml
- Support efficient json extraction within a pandas column HOT 1
- [ENH] implement full numba version of a single conditional_join
- deprecation warning for pivot_longer HOT 1
- Return only matching indices for `conditional_join`
- [ENH] cython a subset of _range_join_indices and equi join HOT 4
- extend `col` powers for index selection HOT 1
- dtype conversion on index
- `conditional_join` fails on mac for `equi-join` and numba HOT 1
- Outdated version in conda forge HOT 1
- extend `row_to_names` to support multiindex
- `sheet_name` not required in jn.xlsx_table
- Problems with equalities in contional_join HOT 18
- Make clean_names() compatible with polars and geopandas dataframes HOT 6
- implement similar functions for polars HOT 4
- perf slower when `sort_by_appearance` is True for `pivot_longer`
- Question about "tabyl()" in pyjanitor HOT 1
- sub-repo for performance optimisations in a lower level language
- add `strip_whitespace` to `clean_names` function
- importing janitor fails HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyjanitor.