Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AttributeError: 'SnowflakeCursor' object has no attribute 'shape'

Is there a way to use "pd.read_sql_query" w/ Snowflake?

I am trying to read my snowflake query in a pandas dataframe, however I get an "Attribute Error" stating ‘SnowflakeCursor’ object has no attribute ‘shape’ (code below) …

Snowflake python connector works. fetch_pandas_all() works. Once I try reading the query as a pandas dataframe, it breaks.

import pyodbc
import sys
import os
import getpass
import snowflake.connector
import pyarrow

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

conn = snowflake.connector.connect(user=’‘, password=’‘, account=’‘, warehouse=’‘, database=’‘, schema=’‘)
cur = conn.cursor()
tenure = cur.execute(
"""SELECT DISTINCT CT_ID, CT_STRT_DATE, MONTHS_BETWEEN(TO_DATE(‘2022-01-01’), TO_DATE(CT_STRT_DATE)) AS TENURE
FROM ..****
WHERE CT_SVC_FREQ != ‘OT’ AND CT_CNCL_DATE IS NULL AND CT_ID LIKE ‘S|%’
ORDER BY CT_STRT_DATE DESC""")

print(tenure.fetch_pandas_all()) — This code works fine

Once I try to manipulate using pandas, I run into errors…

print(tenure.shape) — breaks w/ "Attribute Error"

>Solution :

What about this way:

df_new = tenure.fetch_pandas_all()
total_rows = df_new.shape[0]

Creating a new DF should allow you to run shape

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading