如何使用pymssql将数据帧写入mssql? [英] How to write dataframe into mssql using pymssql?

查看:358
本文介绍了如何使用pymssql将数据帧写入mssql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pymssql将df写入mssql,但是没有用.

I am using pymssql to write a df into mssql, but didn't work.

from sqlalchemy import create_engine
import pymssql
engine = create_engine('mssql+pymssql://sa:suzhou@localhost/test_python')

data.to_sql('phill',engine)

出现以下错误.怎么了?

With an error below. What's wrong?

NoSuchColumnError: "Could not locate column in row for column '0'"

前5行:

    Dc_Dist Psa Dispatch_Date_Time  Dispatch_Date   Dispatch_Time   Hour    Dc_Key  Location_Block  UCR_General Text_General_Code   Police_Districts    Month   Lon Lat
3   35  D   2009-07-19 01:09:00 2009-07-19  01:09:00    1   200935061008    5500 BLOCK N 5TH ST 1500.0  Weapon Violations   20.0    2009-07 -75.130477  40.036389
4   9   R   2009-06-25 00:14:00 2009-06-25  00:14:00    0   200909030511    1800 BLOCK WYLIE ST 2600.0  All Other Offenses  8.0 2009-06 -75.166350  39.969532
5   17  1   2015-04-25 12:50:00 2015-04-25  12:50:00    12  201517017705    800 BLOCK S BROAD ST    600.0   Thefts  13.0    2015-04 -75.166412  39.940070
6   23  K   2009-02-10 14:33:00 2009-02-10  14:33:00    14  200923006310    2200 BLOCK RIDGE AVE    800.0   Other Assaults  16.0    2009-02 -75.171149  39.979586
12  22  3   2015-10-06 18:18:00 2015-10-06  18:18:00    18  201522089374    1500 BLOCK N 15TH ST    600.0   Thefts  16.0    2015-10 -75.160229  39.976134

推荐答案

这是由于sqlalchemy而引起的问题.在我的python坐包中,有SQLAlchemy-1.1.4-py2.7.egg-infoSQLAlchemy-1.1.5.dist-infosqlalchemy.只需删除除sqlalchemy以外的所有内容,即可解决NoSuchColumnError: "Could not locate column in row for column '0'".

It's the problem because of sqlalchemy. In my python sit-packages, there are SQLAlchemy-1.1.4-py2.7.egg-info, SQLAlchemy-1.1.5.dist-info, and sqlalchemy. Just delete all except sqlalchemy, the NoSuchColumnError: "Could not locate column in row for column '0'" will be solved.

这篇关于如何使用pymssql将数据帧写入mssql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆