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.
Use isinstance
:
if isinstance(df, pd.DataFrame):
print('pandas')
else:
print('spark')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With