TypeError: float() argument must be a string or a number, not 'method'

a 夏天 提交于 2019-12-23 15:23:35

问题


I am trying to convert the latitude and longitude to zipcodes for around 10k data points. I am using geocoder for the task.

lat = subsamp['Latitude'].as_matrix
long = subsamp['Longitude'].as_matrix

g = geocoder.google([lat, long], method='reverse')

zip = g.postal

But, on executing the geocoder I get the error:

TypeError: float() argument must be a string or a number, not 'method'

I tried running it using a Pandas series then Numpy array but does not work.


回答1:


Its a Missing parentheses issue for .as_matrix, pandas.DataFrame.as_matrix, is a method used to convert the frame to its Numpy-array representation.

As it is a function, you missed the (), you have not added () function parenthesis, for .as_matrix.

lat = subsamp['Latitude'].as_matrix
long = subsamp['Longitude'].as_matrix

It should be as follows :

lat = subsamp['Latitude'].as_matrix()
long = subsamp['Longitude'].as_matrix()



回答2:


zip is a number or string but you have assigned a function to this value. zip = g.postal -> zip = g.postal()



来源:https://stackoverflow.com/questions/43579753/typeerror-float-argument-must-be-a-string-or-a-number-not-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!