英文:
__init__() got an unexpected keyword argument 'geometry'
问题
I'm trying to get longitude and latitude of areas in Indonesia using dask_geopandas
and Nominatim
library in python pandas dataframe. But, it always returns error. The latest error that I get:
__init__() got an unexpected keyword argument 'geometry'
This is the code I'm using recently:
import dask.dataframe as dd
import dask_geopandas as dask_gpd
import pandas as pd
from geopy.geocoders import Nominatim
import numpy as np
ddf = dd.from_pandas(df_cleaned, npartitions=4)
geolocator = Nominatim(user_agent="my_geocoder")
def geocode_area(area):
try:
location = geolocator.geocode(area)
return (location.latitude, location.longitude)
except:
return (np.nan, np.nan)
ddf['latitude'] = np.nan
ddf['longitude'] = np.nan
ddf['latitude'], ddf['longitude'] = ddf['kodya / kab'].apply(lambda x: pd.Series(geocode_area(x)))
dask_gdf = dask_gpd.GeoDataFrame(ddf, geometry=dask_gpd.points_from_xy(ddf.longitude, ddf.latitude), crs='EPSG:4326')
ddf = dask_gdf.drop columns=['geometry']).compute()
ddf.to_csv('processed_data.csv', index=False)
What is the possible right code for this case? I just want to get a pandas dataframe with longitude and latitude based on kodya / kab
. The dataframe consists of 17000++ rows. Thank u in advance.
英文:
I'm trying to get longitude and latitude of areas in Indonesia using dask_geopandas
and Nominatim
library in python pandas dataframe. But, it always returns error. The latest error that I get:
__init__() got an unexpected keyword argument 'geometry'
This is the code I'm using recently:
import dask.dataframe as dd
import dask_geopandas as dask_gpd
import pandas as pd
from geopy.geocoders import Nominatim
import numpy as np
ddf = dd.from_pandas(df_cleaned, npartitions=4)
geolocator = Nominatim(user_agent="my_geocoder")
def geocode_area(area):
try:
location = geolocator.geocode(area)
return (location.latitude, location.longitude)
except:
return (np.nan, np.nan)
ddf['latitude'] = np.nan
ddf['longitude'] = np.nan
ddf['latitude'], ddf['longitude'] = ddf['kodya / kab'].apply(lambda x: pd.Series(geocode_area(x)))
dask_gdf = dask_gpd.GeoDataFrame(ddf, geometry=dask_gpd.points_from_xy(ddf.longitude, ddf.latitude), crs='EPSG:4326')
ddf = dask_gdf.drop(columns=['geometry']).compute()
ddf.to_csv('processed_data.csv', index=False)
What is the possible right code for this case? I just want to get a pandas dataframe with longitude and latitude based on kodya / kab
. The dataframe consists of 17000++ rows. Thank u in advance.
答案1
得分: 1
你可以尝试使用[from_dask_dataframe][1]替代:
```python
dask_gdf = dask_gpd.from_dask_dataframe(ddf, geometry=dask_gpd.points_from_xy(ddf.longitude, ddf.latitude))
<details>
<summary>英文:</summary>
You can try using [from_dask_dataframe][1] instead:
```python
dask_gdf = dask_gpd.from_dask_dataframe(ddf, geometry=dask_gpd.points_from_xy(ddf.longitude, ddf.latitude))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论