【发布时间】:2023-03-11 21:05:01
【问题描述】:
我正在尝试根据键折叠数据框的行。我的文件很大,pandas 抛出内存错误。我目前正在尝试使用 dask。我在这里附上代码的sn-p。
def f(x):
p = x.groupby(id).agg(''.join).reset_index()
return p
metadf = pd.DataFrame(columns=['c1','p1','pd1','d1'])
df = df.groupby(idname).apply(f, meta=metadf).reset_index().compute()
p 与metadf 具有相同的结构。两个数据框的形状相同。
执行此操作时,出现以下错误:
“ValueError:长度不匹配:预期轴有 6 个元素,新值有 5 个元素”
我在这里缺少什么?有没有其他方法可以根据 dask 中的键折叠行?
The task in hand, to do the following sample in a dask dataframe
Input csv file :
key,c1,c2,c3......,cn
1,car,phone,cat,.....,kite
2,abc,def,hij,.......,pot
1,yes,no,is,.........,hello
2,hello,yes,no,......,help
Output csv file:
key,c1,c2,c3,.......,cn
1,caryes,phoneno,catis,.....,kitehello
2,abchello,defyes,hijno,....,pothelp
【问题讨论】:
标签: dask