当我使用熊猫时,代码运行完美(但速度很慢), 当使用modin和concat数据框时,显示错误
contador = 0
df = pd.DataFrame()
data = pd.DataFrame()
for file in range(len(files)):
usefile = files[file]
print("Valor Numero :" + str(contador) + " de un total de " + str((len(files))) + " archivos")
print("Existe " + str(usefile) + " añadiendolo al DataFrame" )
contador = contador +1
ruta = mainpath + "/" + str(usefile)
df = pd.read_csv(ruta)
datos[usefile] = df
data = pd.concat(datos.values(), keys=datos.keys() , sort='True')
<ipython-input-4-e5a361476e76> in <module>
12 df = pd.read_csv(ruta)
13 datos[usefile] = df
---> 14 data = pd.concat(datos.values(), keys=datos.keys() , sort='True')
15
~/anaconda3/lib/python3.7/site-packages/modin/pandas/concat.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, sort, copy)
98 new_idx_labels = {
99 keys[i]: objs[i].index if axis == 0 else objs[i].columns
--> 100 for i in range(len(objs))
101 }
102 print(new_idx_labels)
~/anaconda3/lib/python3.7/site-packages/modin/pandas/concat.py in <dictcomp>(.0)
98 new_idx_labels = {
99 keys[i]: objs[i].index if axis == 0 else objs[i].columns
--> 100 for i in range(len(objs))
101 }
102 print(new_idx_labels)
TypeError: 'dict_keys' object is not subscriptable
答案 0 :(得分:0)
基于keys
和objs
参数可以下标的假设,这是Modin(版本0.4)中意外支持的行为。
您可以将代码的最后一行更改为一种解决方法,直到在Modin中将其修复为止:
data = pd.concat(list(datos.values()), keys=list(datos.keys()) , sort='True')
我在Modin存储库上创建了一个问题来跟踪该问题:https://github.com/modin-project/modin/issues/557