Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

df.to_sql() Missing Optional Dependency: pandas

SOLVED:

I'm having an issue using sqlalchemy and snowflake.connector to push my df to a new table in Snowflake but I am prompted with this error:

raise errors.MissingDependencyError(self._dep_name) snowflake.connector.errors.MissingDependencyError: Missing optional dependency: pandas

Edit: Accidentally posted without adding in more detail!

I am importing pandas, and all necessary packages. I do not understand why the error is suggesting pandas is missing as it is used elsewhere many times in my scripts.

Versions are:

snowflake-connector-python 3.0.2

snowflake-sqlalchemy 1.4.7

SQLAlchemy 1.4.49

Below is a stripped out example of my code:

import pandas as pd
from snowflake.connector.pandas_tools import pd_writer
from sqlalchemy.types import String
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine

engine = create_engine(URL(
    user='service account',
    password='password',
    account='account',
    database='database',
    schema='schema',
    warehouse='warehouse',
    role="role"
    ))
df.columns = map(lambda x: str(x).upper(), df.columns)

df.to_sql(name=table_name.lower(), con=engine, schema="schema", index=False, if_exists='append', method=pd_writer, dtype={'field': String})

engine.dispose()

Solution:

Run the following in terminal/powershell:

pip install snowflake-connector-python[pandas]

like image 633
Harry Avatar asked Mar 12 '26 22:03

Harry


1 Answers

Moving the answer from the question to the answer section, so it doesn't look as unanswered:

pip install snowflake-connector-python[pandas]
like image 111
Felipe Hoffa Avatar answered Mar 14 '26 10:03

Felipe Hoffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!