TypeError:float()参数必须是字符串或数字,而不是'方法'

时间:2021-05-10 17:06:56

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

我试图将纬度和经度转换为大约10k数据点的zipcodes。我正在使用地理编码器来完成任务。

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'

TypeError:float()参数必须是字符串或数字,而不是'方法'

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

我尝试使用Pandas系列然后Numpy阵列运行它但不起作用。

2 个解决方案

#1


7  

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_matrix,pandas.DataFrame.as_matrix的Missing括号问题,是一种用于将帧转换为Numpy数组表示的方法。

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

因为它是一个函数,你错过了(),你没有为.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


0  

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

zip是一个数字或字符串,但您已为此值指定了一个函数。 zip = g.postal - > zip = g.postal()

#1


7  

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_matrix,pandas.DataFrame.as_matrix的Missing括号问题,是一种用于将帧转换为Numpy数组表示的方法。

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

因为它是一个函数,你错过了(),你没有为.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


0  

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

zip是一个数字或字符串,但您已为此值指定了一个函数。 zip = g.postal - > zip = g.postal()