Python 属性错误:';雪花光标';对象没有属性';光标';

Python 属性错误:';雪花光标';对象没有属性';光标';,python,pandas,snowflake-cloud-data-platform,Python,Pandas,Snowflake Cloud Data Platform,我正在尝试使用to_sql方法将我的数据帧写入Snowflake sf_conn=snowflake.connector.connect( 账户=*****, 用户=*****, 密码=*****, 角色=*****, 仓库=*****, 数据库=***** ) sf\u cur=sf\u conn.cursor() df=pd.DataFrame([('Mark',10),('Luke',20)],columns=['name','balance']) df.to_sql('TEST3',co

我正在尝试使用to_sql方法将我的数据帧写入Snowflake

sf_conn=snowflake.connector.connect(
账户=*****,
用户=*****,
密码=*****,
角色=*****,
仓库=*****,
数据库=*****
)
sf\u cur=sf\u conn.cursor()
df=pd.DataFrame([('Mark',10),('Luke',20)],columns=['name','balance'])
df.to_sql('TEST3',con=sf_cur,schema='public',index=False)
但是还没有运气

File "/home/karma/.local/lib/python3.6/site-packages/pandas/io/sql.py", line 1584, in execute
    cur = self.con.cursor()
AttributeError: 'SnowflakeCursor' object has no attribute 'cursor'
甚至尝试给出
con=sf\u conn
,但得到以下错误:

pandas.io.sql.DatabaseError: Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': not all arguments converted during string formatting

我可以使用sqlAlchemy create_engine lib做同样的工作,但我想专门使用snowflake连接。

回答您的问题:在使用snowflake时,您必须使用sqlAlchemy引擎作为连接

当您使用
df.to_sql
时,您需要传入一个SQLAlchemy引擎,而不是一个标准的雪花连接对象(也不是您尝试过的游标)。您需要使用pip安装
snowflake-sqlalchemy
,但不需要安装
snowflake-connector-python
,因为snowflake-sqlalchemy为您提供了这一功能

下面是一个对我有用的例子:

从sqlalchemy导入创建引擎
导入操作系统
作为pd进口熊猫
雪花_用户名=os.environ['snowflake_用户名']
snowflake_password=os.environ['snowflake_password']
snowflake_account=os.environ['snowflake_account']
snowflake_warehouse=os.environ['snowflake_warehouse']
雪花_数据库='test_db'
雪花_模式='public'
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
引擎=创建引擎(
'snowflake://{user}:{password}@{account}/{db}/{schema}?warehouse={warehouse}'。格式(
user=snowflake\u用户名,
密码=雪花密码,
账户=雪花账户,
db=雪花_数据库,
模式=雪花模式,
仓库=雪花仓库,
)
)
df=pd.DataFrame([('Mark',10),('Luke',20)],columns=['name','balance'])
to_sql('TEST_TABLE',con=engine,schema='public',index=False,如果_exists='append')
每次我运行上述脚本时,Mark和Luke记录都会附加到我的
test\u db.public.test\u表中