Home > Blockchain >  How to change function call to have a more OOP with Pandas
How to change function call to have a more OOP with Pandas

Time:01-19

I want have a function main that when it is called i will also call another functions. I want to make a code where each function has their own class and then at the end will be called from the main class.

my original code

I wanted to change it into class is_date() and class is_number() I dont really have much expertise in OOP with pandas if there are any pointers i would like to know some. thanks!

CodePudding user response:

Don't say "if xxxx is True" or "if xxxx is False". Python lets things have "true-ish" and "false-ish" values without making that conversion. And you usually don't need "if xxx:" / "return 1" / "else:" / "return 0". Just return the thing you're testing. So:

def is_date(s):
    return 1 if re.match(r"\d{4}-\d{2}-\d{2}",s) else 0
def is_number(s):
    return int(s.isdigit())

As a side note, it's not usually very useful to have is_date and is_number as columns, since it's so trivial to compute those values when you need them.

  •  Tags:  
  • Related