Pandas To_sql超出范围错误

时间:2018-05-31 05:56:23

标签: python pandas outofrangeexception

我将来自api的json数据导入到pandas数据框中,并使用pandas.to_sql从数据框中导入到sql数据库中。

API中的某些行包含导致超出范围错误的无效数据。

有没有办法跳过或丢弃这些行而不是程序失败?

错误来自于尝试插入' 1900-01-01T00:00:00Z'到SQL中的datetime字段。

错误响应:DataError:(pyodbc.DataError)(' 22007',' [22007] [Microsoft] [SQL Server的ODBC驱动程序11] [SQL Server] nvarchar的转换数据类型为日期时间数据类型导致超出范围的值。(242)(SQLExecDirectW)')[SQL:' INSERT INTO [TEMP_well_origin]([Abstract],[Basin],[机密],[机密日期],[国家],[县],[CreatedDate],[CurrentOperator],[CurrentStatus],[CurrentStatusDate],[DeletedDate],[DepthUom],[District],[ElevRefDatum],[ElevRefDatumepsgCode] ,[ElevUom],[Environment],[Field],[FluidType],[Formation],[GovernmentID],[GroundElev],[InitialClassification],[LeaseName],[LeaseNumber],[LicenseDate],[OnProductionDate],[ OriginalOperator],[PermitNumber],[ProvinceState],[Range],[RangeDirection],[Region],[Remark],[Section],[Source],[SpudDate],[Township],[TownshipDirection],[UID] ,[UpdatedDate],[WaterDepth],[WaterDepthDatum],[WellName],[WellNumber],[Wgs84Latitude],[Wgs84Longitude])VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'] [参数:((无,' ANADARKO BASIN' N',无,'美国',' KINGFISHER',' ; 2017-06-14T17:53:36.853Z',' GASTAR EXPL',' PERMITTED',' 2017-06-13T00:00:00Z' ,没有,' ft',无,' MSL',5714,' ft',无,' UNKNOWN',' OIL &安培; GAS',' WOODFORD',3507325671,1121.0,无,' STOWEY 1907',无,' 2017-06-13T00:00:00Z',无,没有,' TEMP25671A',' OKLAHOMA',7.0,' W','北美洲'无,14.0,' DI',无,19.0,' N',18965913,' 2018-04-13T21:06:55.96Z',无,' MSL',& #39; STOWEY 1907',#11; 11-1LOH',36.1304886,-97.9171516),(无,' ANADARKO BASIN',' N',无, '美国',' KINGFISHER' 2017-06-14T17:53:36.853Z',' MARATHON OIL',' ; ACTIVE',' 2017-07-19T00:00:00Z',无,' ft',无,' MSL',5714,' ; ft',无,' UNKNOWN',' OIL',' MISSISSIPPIAN',3507325669,1088.0,无,' WHITE 1607' ,732191770.0,' 2017-06-12T00:00:00Z',' 2017-08-01T00:00:00Z',无,' TEMP25669',&# 39; OKLAHOMA',7.0,' W','北美洲',无,13.0,' DI',' 2017-06-19T00 :00:00Z ',16.0,' N',18965897,' 2017-11-23T10:44:37.41Z',无,' MSL',&#39 ; WHITE 1607',' 1-130H',35.8707209,-97.9037809),(无,' ANADARKO BASIN',' N',无,&# 39;美国',' ELLIS' 2017-06-14T17:53:36.853Z',' JONES ENERGY',' P &安培; A',' 1900-01-01T00:00:00Z',无,' ft',无,' MSL',5714,' ft',无,' UNKNOWN',' OIL& GAS',' CLEVELAND',3504523668,2422.0,无,' OBLANDER 28',无,' 2017-06-13T00:00:00Z',无,没有,' TEMP23668',' OKLAHOMA',25.0,' W','北美洲'无,28.0,' DI',' 2017-07-03T00:00:00Z',20.0,' N',18965889,' 2018-03-22T08:55:31.79Z&# 39;,无,' MSL',' OBLANDER 28',' 1H',36.1866636,-99.8803567),(无,' ANADARKO BASIN' ;,' N',无,'美国'' BLAINE',' 2017-06-14T17:53:36.853Z', ' CHESAPEAKE',' INACTIVE',' 2017-08-20T00:00:00Z',无,' ft',无,&# 39; MSL',5714,' ft',无,' UNKNOWN',' OIL',' MISSISSIPPIAN',3501123814,1388.0 ,无,' NUGGET 34-20-12',932192050.0,' 2017-06-13T00:00:00Z',无,无,' TEMP23814',& #39; OKLAHOMA',12.0,' W','北美洲',无,34.0,' DI',' 2017-06- 24T00:00:00Z&# 39;,20.0,' N',18965888,' 2017-12-04T10:37:36.05Z',无,' MSL',' NUGGET 34-20-12',' 1HC',36.1591637,-98.475103),(无,' CHAUTAUQUA PLATFORM',' N',无,&# 39;美国',' PAYNE' 2017-06-14T17:53:36.853Z',' WHITE STAR PETR',' ; INACTIVE',' 2017-06-12T00:00:00Z',无,' ft',无,' MSL',5714,&#39 ; ft',无,' PRAIRIE VIEW EAST' OIL',' MISSISSIPPIAN',3511924431,1117.0,无,' BETTY JEAN 26 -19N-1W',1192192560.0,' 2017-06-12T00:00:00Z',无,无,' TEMP24431',' OKLAHOMA',1.0 ,' W','北美洲',无,26.0,' DI',' 2017-08-04T00:00:00Z', 19.0,' N',18965882,' 2017-12-04T10:37:36.05Z',无,' MSL',' BETTY JEAN 26- 19N-1W',' 2MH',36.087479,-97.2757837),(无,' CHAUTAUQUA PLATFORM' N',无,'美国&# 39;,' PAYNE',' 2017-06-14T17:53:36.853Z',' WHITE STAR PETR' INACTIVE' ,' 2017-06-12T00:00:00Z',无,' ft',无,' MSL',5714,' ft' ,没有,' PRAIRIE VIEW EAST' OIL',' MISSISSIPPIAN',3511924430,1113.0,无,' BETTY JEAN 26-19N-1W&# 39;,1192192550.0,' 2017-06-12T00:00:00Z',无,无,' TEMP24430',' OKLAHOMA',1.0,' W','北美洲',无,26.0,' DI' 2017-07-24T00:00:00Z',19.0,&#39 ; N',18965881,' 2018-05-30T09:36:45.16Z',无,' MSL',' BETTY JEAN 26-19N-1W&#39 ;,' 1MH',36.087479,-97.2758829),(无,' ANADARKO BASIN' N',无,'美国' ,' KINGFISHER' 2017-06-14T17:53:36.853Z',' NEWFIELD EXPL',' ACTIVE',&#39 ; 2017-08-06T00:00:00Z',无,' ft',无,' MSL',5714,' ft',无,& #39; OKARCHE NORTH',' OIL& #39;,' MISSISSIPPIAN',3507325668,1156.0,无,' ROBERT',732191660.0,' 2017-06-12T00:00:00Z',' ; 2017-08-01T00:00:00Z',无,' TEMP25668',' OKLAHOMA',7.0,' W',' NORTH AMERICA',无,21.0,' DI',' 2017-06-13T00:00:00Z',15.0,' N',18965765,&# 39; 2018-03-22T08:55:31.79Z',无,' MSL',' ROBERT',' 1507 1H-21',35.7557449, -97.9433457),(无,' SOUTH OKLAHOMA FOLDED BELT',' N',无,'美国'' CARTER',& #39; 2017-06-14T17:53:36.853Z',' AVALON OPERATING LLC',' PERMITTED',' 2017-06-14T00:00:00Z& #39;,无,' ft',无,' MSL',5714,' ft',无,' UNKNOWN',&# 39; OIL& GAS',' HUNTON(LS CHIMNEY HILL)',3501926276,958.0,无,' DOC BROWN',无,' 2017-06-14T00:00: 00Z',无,无,' TEMP26276',' OKLAHOMA',2.0,' W','北美洲',无, 30.0,' DI',无,3.0,' S',18965755,' 2018-04-13T21:06:55.96Z',无,' MSL',' DOC BROWN' 2-30-19XH',34.2629504,-97.4414937)...显示1000个总约束参数集中的10个......(无, ' CHAUTAUQUA PLATFORM' N',无,'美国'' PAYNE',' 2017-01-29T02: 24:26.803Z','(N / A)','非活动',无,无,' ft',无,' MSL',5714,' ft',无,' UNKNOWN',' UNKNOWN','(N / A)', 3511902537,888.94,无,' CATES',无,无,无,无,无,' OKLAHOMA',5.0,' E',' NORTH AMERICA',无,32.0,' DI',无,18.0,' N',18951364,' 2018-05-30T09:36:45.16Z' ,没有,' MSL',' CATES' 1-A',35.996081,-96.79559),(无,' CHAUTAUQUA PLATFORM', ' N',无,'美国'' WAGONER',' 2017-01-29T02:24:26.803Z',&# 39;(N / A)','非活动',无,无,' ft',无,' MSL',5714,&#39 ; ft',无,' UNKNOWN',' UNKNOWN','(N / A)',3514505289,527.91,无,' SHAFFER',无,无,无,无,无,' OKLAHOMA',17.0,' E','北美洲',无,1.0,& #39; DI',无,16.0,' N',18951363,' 2018-05-30T09:36:45.16Z',无,' MSL&#39 ;,' SHAFFER',' 1',35.8872222,-95.4483611))](关于此错误的背景:http://sqlalche.me/e/9h9h

0 个答案:

没有答案