Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if a dataframe is Pandas or Spark?

I pass a dataframe to a function. Sometimes it is Pandas dataframe, and sometimes it is a Spark dataframe. My function will need to act accordingly. Is there a simple method, such as df.isPandas(), to determine if a dataframe (received as "df") is a Pandas dataframe or a Spark dataframe? Thanks in advance.

like image 459
Bill Qualls Avatar asked Sep 05 '25 00:09

Bill Qualls


1 Answers

Use isinstance :

if isinstance(df, pd.DataFrame):
    print('pandas')
else:
    print('spark')
like image 107
Space Impact Avatar answered Sep 07 '25 23:09

Space Impact