Dask 错误:值的长度与索引的长度不匹配 [英] Dask error: Length of values does not match length of index

查看:79
本文介绍了Dask 错误:值的长度与索引的长度不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 dask 以这种方式读取了 csv 文件:

I have read csv file using dask this way:

import dask.dataframe  as dd
train = dd.read_csv('act_train.csv')

然后我想每行应用简单的逻辑,这在熊猫中工作得很好:

Then I would like to apply simple logic per row , that works pretty fine in pandas:

columns = list(train.columns)

for col in columns[1:]:
    train[col] = train[col].apply(lambda x: x if x == -1 else x.split(' ')[1])

不幸的是,最后一行代码生成以下错误:值的长度与索引的长度不匹配

Unfortunately, last line of code generates the following error: Length of values does not match length of index

我做错了什么?

推荐答案

如果 x 不包含空格字符,则 x.split(' ') 将返回一个包含单个元素 x 的列表.

If x doesn't contain space character than x.split(' ') will return a list containing single element x.

因此,当您尝试通过调用访问 x.split(' ') 的第二个元素时x.split(' ')[1].它会给出错误:

So, when u are trying to access the second element of x.split(' ') by calling x.split(' ')[1]. It will give the error :

值的长度与索引的长度不匹配",因为 x.split(' ') 中索引 1 处没有元素.

"Length of values does not match length of index", as there is no element at index 1 in x.split(' ').

这篇关于Dask 错误:值的长度与索引的长度不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆