Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change function call to have a more OOP with Pandas

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading