1 0
Read Time:1 Minute, 51 Second

Pandas a library for data analysis. With Pandas, you use a data structure called a DataFrame to analyze and manipulate two-dimensional data (such as data from a database table). Snowflake allows easy integration with custom and packaged tools and applications. It provides connectors for not only Python but also ODBC, JDBC, Javascript, Spark, R, and Node. js . Snowflake Python Connector is being used to get data from a Snowflake database to a Pandas DataFrame.

Pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series. 

To write data from a Pandas DataFrame to a Snowflake database, do one of the following:

  • Call the write_pandas() function.
  • Call the pandas. DataFrame. to_sql() method (see the Pandas documentation), and specify pd_writer() as the method to use to insert the data into the database.
Native Snowflake Python

Universal Python Snowflake Connectivity: Easily connect to Snowflake data from common Python-based frameworks, including:

  • Data Analysis/Visualization: Jupyter Notebook, pandas, Matplotlib
  • ORM: SQLAlchemy, SQLObject, Storm
  • Web Applications: Dash, Django

To get data from a Snowflake database into Pandas , you can use the API methods provided with the Snowflake Connector for Python. The connector also provides API methods for writing data from a Pandas DataFrame to a Snowflake database.

import snowflake.connector as sf
import pandas as pd
user='sachinsnowpro'
password='XXXXXXXX'
account='cca45723.XXXX.XXXX' ### This can be found in your snowflake account URL. Example eca00000.us-east-1 (if using AWS cloud)
database='DEMO_DB'
warehouse='COMPUTE_WH'
schema = 'PUBLIC'
role = 'SYSADMIN'
conn = sf.connect(user = user,
password = password,
account = account,
warehouse =warehouse,
database =database,
schema =schema,
role =role
)
drop_obj = "drop table if exists emp_test"
temp_obj = "create table emp_test as select * from employee"

# ---- try Clause for python cursor
try:
conn.cursor().execute(drop_obj)
conn.cursor().execute(temp_obj)

except Exception as e:
print(e)

try:
for (col1, col2,col3) in conn.cursor().execute("SELECT id, name,department FROM emp_test"):
print('{0}, {1},{2}'.format(col1, col2,col3))

except Exception as e:
print(e)

finally:
conn.close()

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *