从数据帧中删除列时出现dask问题(最新dask 2021.04.1)

2024-10-01 02:32:50 发布

您现在位置:Python中文网/ 问答频道 /正文

代码如下:

import pandas as pd
import dask.dataframe as dd
import numpy as np
a = pd.DataFrame({'A':["None",None,None,None,None],'insuredid':[34,90,7779,56,46],'LONGITUDE':[12,34.99,7779.9,56.9,46.90], 'LATITUDE': [12,34.99,np.nan,56.9,46.90]})  
a['EXPTYPE'] = " "
a=dd.from_pandas(a,npartitions=1)
b =pd.DataFrame({'f':[None,None,None,None,None],'insuredid':[34,89,7779,78,46],'test':[12,34.99,7779.9,56.9,46.90]})
b=dd.from_pandas(b,npartitions=1)
a = dd.merge(a,b , how='left' , on ='insuredid').drop(['LATITUDE', 'LONGITUDE'],axis=1)

但这是它显示的错误,而不是所需的输出:

a = dd.merge(a,b , how='left' , on ='insuredid').drop(columns= ['LATITUDE', 'LONGITUDE'],axis=1)

a.head()

获取以下错误

ValueError: Metadata inference failed in `drop_by_shallow_copy`.

You have supplied a custom function and Dask is unable to
determine the type of output that that function returns.

To resolve this please provide a meta= keyword.
The docstring of the Dask function you ran should have more information.

Original error is below:
------------------------
KeyError('[None] not found in axis')

Tags: fromimportnonedataframepandasasnpfunction