`__init__()`收到了一个意外的关键字参数’geometry’。

huangapple go评论71阅读模式
英文:

__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))

huangapple
  • 本文由 发表于 2023年2月24日 16:18:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554094.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定