1
import proximityhash

# filtering the dataset with the required columns 
df_new=df.filter(['latitude', 'longitude','cell_radius'])

# assign the column  values to a variable
latitude = df_new['latitude']
longitude = df_new['longitude']
radius= df_new['cell_radius']
precision = 7

# passing the variable as the parameters to the proximityhash library 
# getting the values and assigning those to a new column as proximityhash
df_new['proximityhash']=df_new.apply([proximityhash.create_geohash(latitude,longitude,radius,precision=7)])
        
print(df_new) 

I had used this code where I imported some dataset and using that dataset I tried to filter the necessary columns and assign them to 3 variables (latitude, longitude, radius) and tried to create a new column as "proximityhash" to the new dataframe but it shows an error like below:

[enter image description here][1]

 [1]: https://i.stack.imgur.com/2xW8S.png


TypeError                                 Traceback (most recent call last)
Input In [29], in <cell line: 15>()
     11 import pygeohash as gh
     13 import proximityhash
---> 15 df_new['proximityhash']=df_new.apply([proximityhash.create_geohash(latitude,longitude,radius,precision=7)])
     17 print(df_new)

File ~\Anaconda3\lib\site-packages\proximityhash.py:57, in create_geohash(latitude, longitude, radius, precision, georaptor_flag, minlevel, maxlevel)
     54 height = (grid_height[precision - 1])/2
     55 width = (grid_width[precision-1])/2
---> 57 lat_moves = int(math.ceil(radius / height)) #4
     58 lon_moves = int(math.ceil(radius / width)) #2
     60 for i in range(0, lat_moves):

File ~\Anaconda3\lib\site-packages\pandas\core\series.py:191, in _coerce_method.<locals>.wrapper(self)
    189 if len(self) == 1:
    190     return converter(self.iloc[0])
--> 191 raise TypeError(f"cannot convert the series to {converter}")

TypeError: cannot convert the series to <class 'float'>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

Figured out a way to solve this, Posting the answer since it might be helpful for others.

Defined a function and pass the library to that specific column

# filtering the dataset with the required columns 
df_new=df[['latitude', 'longitude','cell_radius']]

# getting a specified row (Since running the whole process might kill the kernel)
df_new = df_new.iloc[:100, ]

# predefined the precision value.
precision = 7

def PH(row):
    latitude = row['latitude']
    longitude = row['longitude']
    cell_radius = row['cell_radius']
    row['proximityhash'] = [proximityhash.create_geohash(float(latitude),float(longitude),float(cell_radius),precision=7)]
    return row

df_new = df_new.apply(PH, axis=1)  

df_new['proximityhash'] =pd.Series(df_new['proximityhash'], dtype="string")
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459