ModuleNotFoundError: No module named 'pandas'

I created a Python model bellow

*import pandas as pd*
*def model(dbt, session):*
*     old = dbt.ref("stg_hbam__attorneys")*
*     new = dbt.ref("stg_hbam__attorneys")*
*     key = 'ATTORNEY_ID'*
*     df_merge = pd.merge(old, new, on=key,suffixes=("_old", "_new"))*
*     df_merge = df_merge.fillna(0)*
*     *
*     return df_merge.limit(10)*

I have upgraded to dbt v1.3 and get an error ModuleNotFoundError: No module named ‘pandas’.
How can I import Python library in dbt?

Which platform are you using? Snowflake?

Yes, I’m using Snowflake

Have you defined your dependency as shown in the configuring packages docs?

See also Python models | dbt Developer Hub which talks about the anaconda specific details for Snowpark

you will also need to call .to_pandas() on the dataframes if using pandas, otherwise they default to Snowpark dataframes

1 Like