Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

when my function f is called with a variable I want to check if var is a pandas dataframe:

def f(var):

    if var == pd.DataFrame():

        print "do stuff"

I guess the solution might be quite simple but even with

def f(var):

    if var.values != None:

        print "do stuff"

I can't get it to work like expected.

1 Answer

0 votes
by (41.4k points)

Use the built-in isinstance() function:

import pandas as pd

def f(var):

    if isinstance(var, pd.DataFrame):

        print("do stuff")

Browse Categories

...