日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python字符串转float出错_值错误:无法将字符串转换为float,NumPy

發布時間:2024/1/23 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python字符串转float出错_值错误:无法将字符串转换为float,NumPy 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我有一個腳本,其中我正在向Esri文件geodatabase寫入一個JSON web服務。我收到錯誤值錯誤:無法將字符串轉換為浮點:微波

我以前使用過完全相同的腳本,U40是所有字符串的數據類型。在

我的腳本和結果如下import json

import jsonpickle

import requests

import arcpy

import numpy

fc = "C:\MYLATesting.gdb\MYLA311"

if arcpy.Exists(fc):

arcpy.Delete_management(fc)

f = open('C:\Users\Administrator\Desktop\myla311.json', 'r')

data = jsonpickle.encode( jsonpickle.decode(f.read()) )

url = "myUrl"

headers = {'Content-type': 'text/plain', 'Accept': '/'}

r = requests.post(url, data=data, headers=headers)

sr = arcpy.SpatialReference(4326)

decoded = json.loads(r.text)

SRAddress = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['SRAddress']

latitude = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['Latitude']

longitude = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['Longitude']

CommodityType = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['ListOfLa311ElectronicWaste']['La311ElectronicWaste'][0]['Type']

ItemType = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['ListOfLa311ElectronicWaste']['La311ElectronicWaste'][0]['ElectronicWestType']

ItemCount = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['ListOfLa311ElectronicWaste']['La311ElectronicWaste'][0]['ItemCount']

CommodityType1 = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['ListOfLa311ElectronicWaste']['La311ElectronicWaste'][1]['Type']

ItemType1 = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['ListOfLa311ElectronicWaste']['La311ElectronicWaste'][1]['ElectronicWestType']

ItemCount1 = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['ListOfLa311ElectronicWaste']['La311ElectronicWaste'][1]['ItemCount']

print SRAddress

print latitude

print longitude

print CommodityType

print ItemType

print ItemCount

print CommodityType1

print ItemType1

print ItemCount1

item ={'SRAddress': SRAddress, 'Longitude': longitude, 'Latitude': latitude, 'CommodityType': CommodityType, 'ItemType': ItemType, 'ItemCount': ItemCount}

import numpy as np #NOTE THIS

keys = ['SRAddress','Longitude','Latitude','CommodityType','ItemType', 'ItemCount']

k1,k2,k3, k4, k5, k6 = keys

data_line ={'SRAddress': SRAddress, 'Longitude': longitude, 'Latitude': latitude, 'CommodityType': CommodityType, 'ItemType': ItemType, 'ItemCount': ItemCount}

frmt = '\nStraight dictionary output\n Address: {} Long: {} Lat: {}'

print(frmt.format(item[k1],item[k2],item[k3], item[k4],item[k5], item[k6]))

print '\noption 1: List comprehension with unicode'

a = tuple([unicode(item[key]) for key in keys]) # list comprehension with unicode

print('{}'.format(a))

dt = np.dtype([('SRAddress','U40'),('CommodityType','U40'), ('ItemType','U40'), ('ItemCount','U40'),('longitude','

arr = np.array(a,dtype=dt)

print'\narray unicode\n',arr

print'dtype',arr.dtype

print '\noption 2:List comprehension without unicode'

b = tuple([item[key] for key in keys])

print('{}'.format(b))

dt = np.dtype([('SRAddress','U40'),('CommodityType','U40'), ('ItemType','U40'), ('ItemCount','U40'),('longitude','

arr = np.array(b,dtype=dt)

print'\narray without unicode\n',arr

print'dtype',arr.dtype

arcpy.da.NumPyArrayToFeatureClass(arr, fc, ['longitude', 'latitude'], sr)

結果

^{pr2}$

總結

以上是生活随笔為你收集整理的python字符串转float出错_值错误:无法将字符串转换为float,NumPy的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。