1
我正在嘗試將編碼函數應用於數據框。我不斷滿足一個ValueError:在數據框上應用python-geohash編碼函數
>>> import pandas as pd
>>> import pygeohash as gh
>>> data = { 'latitude': [4.123, 24.345, 31.654], 'longitude': [25.432, 4.234, 57.098]}
>>> df = pd.DataFrame(data)
>>> df
latitude longitude
0 4.123 25.432
1 24.345 4.234
2 31.654 57.098
>>> df['geohash']=df.apply(lambda x: gh.encode(df.latitude, df.longitude, precision=5), axis=1)
Traceback (most recent call last):
.........
ValueError: ('The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().', 'occurred at index 0')
>>>
在一對價值的推杆:
>>> gh.encode(22,36, precision = 5)
'sgct5'
顯示gh.encode工作。
有沒有其他方式做到這一點?