GithubHelp home page GithubHelp logo

Comments (12)

szuckerman avatar szuckerman commented on August 20, 2024 2

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.

szuckerman avatar szuckerman commented on August 20, 2024 1

The above looks good, except “exact” is unnecessary. Regex or glob without wildcards will be equivalent.

from pyjanitor.

ericmjl avatar ericmjl commented on August 20, 2024 1

Needs a column_name / col_name (?), right?

Thank you. Updating...

from pyjanitor.

zbarry avatar zbarry commented on August 20, 2024 1

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.

ericmjl avatar ericmjl commented on August 20, 2024 1

@zbarry good point! Updated the function signature.

from pyjanitor.

zbarry avatar zbarry commented on August 20, 2024

Should it support regular expressions?
🤔

from pyjanitor.

szuckerman avatar szuckerman commented on August 20, 2024

Regex is ok.... but globbing is nicer:

https://docs.python.org/3.6/library/fnmatch.html

from pyjanitor.

ericmjl avatar ericmjl commented on August 20, 2024

@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.

ericmjl avatar ericmjl commented on August 20, 2024

Ok, got it! Pardon my ignorance here, but is globbing a "subset" of regexing, or there mutually exclusive parts to them?

from pyjanitor.

zbarry avatar zbarry commented on August 20, 2024

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.

ericmjl avatar ericmjl commented on August 20, 2024

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.

zbarry avatar zbarry commented on August 20, 2024

Needs a column_name / col_name (?), right?

from pyjanitor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.