check if variable is dataframe

前端 未结 2 1578
终归单人心
终归单人心 2020-12-04 09:56

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         


        
2条回答
  •  天命终不由人
    2020-12-04 10:29

    Use the built-in isinstance() function.

    import pandas as pd
    
    def f(var):
        if isinstance(var, pd.DataFrame):
            print("do stuff")
    

提交回复
热议问题