- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 panda 分析 JSON 文件:https://data.cityofnewyork.us/api/views/kpav-sd4t/rows.json?accessType=DOWNLOAD
一切顺利,直到我到达终点将我的信息从 panda 传输到 SQL。
我输入:
df.to_sql('table', con, chunksize=20000)
但结果是
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
1399 else:
-> 1400 cur.execute(*args)
1401 return cur
/usr/lib/python3/dist-packages/MySQLdb/cursors.py in execute(self, query, args)
209 query = query.decode(db.unicode_literal.charset)
--> 210 query = query % args
211
TypeError: not all arguments converted during string formatting
During handling of the above exception, another exception occurred:
DatabaseError Traceback (most recent call last)
<ipython-input-25-a485028ed4c0> in <module>()
----> 1 df.to_sql('table', con, chunksize=20000)
/usr/local/lib/python3.5/dist-packages/pandas/core/generic.py in to_sql(self, name, con, flavor, schema, if_exists, index, index_label, chunksize, dtype)
1199 sql.to_sql(self, name, con, flavor=flavor, schema=schema,
1200 if_exists=if_exists, index=index, index_label=index_label,
-> 1201 chunksize=chunksize, dtype=dtype)
1202
1203 def to_pickle(self, path):
/usr/local/lib/python3.5/dist-packages/pandas/io/sql.py in to_sql(frame, name, con, flavor, schema, if_exists, index, index_label, chunksize, dtype)
468 pandas_sql.to_sql(frame, name, if_exists=if_exists, index=index,
469 index_label=index_label, schema=schema,
--> 470 chunksize=chunksize, dtype=dtype)
471
472
/usr/local/lib/python3.5/dist-packages/pandas/io/sql.py in to_sql(self, frame, name, if_exists, index, index_label, schema, chunksize, dtype)
1499 if_exists=if_exists, index_label=index_label,
1500 dtype=dtype)
-> 1501 table.create()
1502 table.insert(chunksize)
1503
/usr/local/lib/python3.5/dist-packages/pandas/io/sql.py in create(self)
581
582 def create(self):
--> 583 if self.exists():
584 if self.if_exists == 'fail':
585 raise ValueError("Table '%s' already exists." % self.name)
/usr/local/lib/python3.5/dist-packages/pandas/io/sql.py in exists(self)
569
570 def exists(self):
--> 571 return self.pd_sql.has_table(self.name, self.schema)
572
573 def sql_schema(self):
/usr/local/lib/python3.5/dist-packages/pandas/io/sql.py in has_table(self, name, schema)
1511 "WHERE type='table' AND name=%s;") % wld
1512
-> 1513 return len(self.execute(query, [name, ]).fetchall()) > 0
1514
1515 def get_table(self, table_name, schema=None):
/usr/local/lib/python3.5/dist-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
1410 ex = DatabaseError(
1411 "Execution failed on sql '%s': %s" % (args[0], exc))
-> 1412 raise_with_traceback(ex)
1413
1414 @staticmethod
/usr/local/lib/python3.5/dist-packages/pandas/compat/__init__.py in raise_with_traceback(exc, traceback)
337 if traceback == Ellipsis:
338 _, _, traceback = sys.exc_info()
--> 339 raise exc.with_traceback(traceback)
340 else:
341 # this version of raise is a syntax error in Python 3
/usr/local/lib/python3.5/dist-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
1398 cur.execute(*args, **kwargs)
1399 else:
-> 1400 cur.execute(*args)
1401 return cur
1402 except Exception as exc:
/usr/lib/python3/dist-packages/MySQLdb/cursors.py in execute(self, query, args)
208 if not PY2 and isinstance(query, bytes):
209 query = query.decode(db.unicode_literal.charset)
--> 210 query = query % args
211
212 if isinstance(query, unicode):
DatabaseError: Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': not all arguments converted during string formatting
我使用
连接到我的服务器con = mdb.connect(host = 'localhost',
user = 'root',
passwd = 'dwdstudent2015',
charset = 'utf8', use_unicode=True)
和
engine = con
我不明白为什么它不起作用
我看过其他例子,但他们没有翻译
最佳答案
DataFrame.to_sql
的con
参数可以是either a SQLAlchemy engine oran sqlite connection .
如果您正在使用 MySQL(和 MySQLdb Python 适配器),那么您必须连接使用 SQLAlchemy engine 到它:
import sqlalchemy as SA
engine = SA.create_engine('mysql+mysqldb://{u}:{p}@{h}/{d}'.format(
u=USER, p=PASSWORD, h=HOST, d=DATABASE'))
df.to_sql('table', engine, chunksize=20000)
注意错误说
DatabaseError: Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': not all arguments converted during string formatting
此 SQL 语句引用 sqlite_master
因为 Pandas 假设连接到 sqlite 数据库。 Pandas 将生成以 sqlite 为中心的 SQL,如果通过了一个连接。如果传递了一个,它将使用 SQLAlchemy 生成 SQLSQLAlchemy 引擎。
关于mysql - 试图将 Pandas 数据帧传输到 mySQL 数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41028233/
我一直在做一些关于测量数据传输延迟的实验 CPU->GPU 和 GPU->CPU。我发现对于特定消息大小,CPU->GPU 数据传输速率几乎是 GPU->CPU 传输速率的两倍。谁能解释我为什么会这样
我将 ElasticSearch 用作我的 Post 模型的 Rails pet 项目应用程序的全文引擎。在我的 posts_controller.rb 索引操作中: def index
概述 流经网络的数据总是具有相同的类型:字节,这些字节如何传输主要取决于我们所说的网络传输。用户并不关心传输的细节,只在乎字节是否被可靠地发送和接收 如果使用 Java 网络编程,你会发现,某些时候当
我正在编写一些代码,以便将共享点从该页面转移到另一个页面: Server.Transfer("/DefectManagement/DefectList/default.aspx") 但是我遇到了这个问
我有这个泄漏,任何猜测?这个类有一些奇怪的引用。我的代码的任何地方都没有 contentobserver In com.example:1.5.0:27. com.example.ui.record
我听说过点对点内存传输并阅读了一些关于它的内容,但无法真正理解与标准 PCI-E 总线传输相比它的速度有多快。 我有一个使用多个 GPU 的 CUDA 应用程序,我可能对 P2P 传输感兴趣。我的问题
ftping 文件时,Transmit 中是否有忽略或过滤器列表?我希望它忽略上传 .svn 文件等。 最佳答案 是的。转到首选项并选择 Rules标签。在那里您可以定义要跳过哪些文件的规则。实际上,
我有以下片段来生成声音,在 while 循环中,我想动态更改它,以便它在声音生成期间创建不同频率的声音。 for(uint16_t i = 0; i < sample_N; i++) { da
我正在尝试使用 Delphi 2010 和 Indy 对 Web 服务进行概念验证。我此时的代码是: procedure TForm1.Log(const sEvent, sMsg: String);
我有一个 ActiveMQ JMS 代理,在端口 61616 上使用默认的 openwire TCP 传输公开。 我有许多远程客户端可以绑定(bind)到此代理来监听他们的消息。 如果我想打开 kee
reconnection strategies文档仅使用 JMS 示例,但是 FTP transport documentation确实说明了重新连接策略的使用,但没有任何细节或示例。 进一步,如果你
我有 2 个 TreeView,第一个填充有项目。 try { CheckBoxTreeItem treeRoot = new CheckBoxTreeItem("Root"); tr
在我为学校开发的一个网站上,用户输入他们的学校电子邮件和密码,如果他们已注册,则登录。如果没有,则会显示登录的第二部分,要求输入笔名称并确认密码。正因为如此,以及我复杂的业余 Django 编程,我有
我正在开发一个 Web 服务,我们在其中使用 LINQ-to-SQL 进行数据库抽象。当客户使用我们的网络服务时,对象被序列化为 XML,一切都很好。 现在我们希望开发我们自己的使用本地数据类型的客户
我应该创建一个名为“Backwards”的方法,该方法将列表从尾部横向到头部,但是当我运行代码时,它出现说(第 88 行)它找不到光标 = cusor.prev;象征。我需要在循环中再次设置上一个链接
给定像 Uint8Array 这样的类型化数组,似乎有两种方法可以通过 worker 传输它们。 选项 1 直接发送缓冲区并在接收端进行转换: 发件人:postMessage({fooBuffer:
在 PHP + jQuery 环境中,我和我的 friend 无法得出最佳解决方案。我们正在使用 Ajax 从数据库中获取数据。 解决方案 1 - Ajax 应该只传输数据,而不是 HTML 好处:我
大家好,非常感谢您的宝贵时间。 有一个 std::stringstream 需要传输到远程机器。网络库允许我用以下方法构建数据包: CreatePacket( const void * DATA, s
我正在使用 libcurl 通过 FTP 传输二进制文件 (.exe),并将其保存到本地文件。问题是文件传输后,它已被更改,不再是有效的 Win32 应用程序,因此无法运行。这是我的做法: CURL
各位程序员, 当我将它上传到我的 FTP 时,我的网站出现此错误:资源被解释为样式表,但使用 MIME 类型文本/纯文本传输 BlahBlahi
我是一名优秀的程序员,十分优秀!