>> lines = sc.textFile(','.join(files)) >>> rdd1 = lines.filter(lambda line: len(line.strip()) > 0) >>> rdd2 = rdd1.map(lambda x: int(x.strip())) >>> sorted_rdd = rdd2.sortBy(lambda x: x) 24/04/...-DPDK中文网" />

ZBLOG

>>> files = ["file1.txt", "file2.txt", "file3.txt"] >>> lines = sc.textFile(','.join(files)) >>> rdd1 = lines.filter(lambda line: len(line.strip()) > 0) >>> rdd2 = rdd1.map(lambda x: int(x.strip())) >>> sorted_rdd = rdd2.sortBy(lambda x: x) 24/04/...

根据错误信息,代码在执行rdd2 = rdd1.map(lambda x: int(x.strip()))这一行时引发了异常。异常是ValueError: invalid literal for int() with base 10: '100,23432,12,123',表明有一个值无法解析为整数。

这个问题可能是由于文件中的某一行包含了一个或多个逗号导致的。你使用,将文件路径连接起来作为参数传递给textFile()函数,所以Spark将会将这些文件合并成一个RDD。然后在执行转换操作时,遇到了一个包含逗号的行,导致无法将其解析为整数。

要解决这个问题,你可以考虑以下几种方法:

  1. 检查文件内容:仔细检查每个文件中的内容,确保没有包含不需要的特殊字符(如逗号)。

  2. 更改分隔符:如果你想使用逗号作为文件路径之间的分隔符,那么请确保文本文件中不会出现逗号。否则,请选择其他合适的分隔符来代替。

  3. 分别加载每个文件:如果你想独立处理每个文件,并避免合并它们时发生冲突,请使用多个sc.textFile()语句分别加载每个文件,并对它们进行单独处理。

希望以上建议能帮助你解决问题。如果还有其他疑问,请随时提问。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:>> lines = sc.textFile(','.join(files)) >>> rdd1 = lines.filter(lambda line: len(line.strip()) > 0) >>> rdd2 = rdd1.map(lambda x: int(x.strip())) >>> sorted_rdd = rdd2.sortBy(lambda x: x) 24/04/...">https://sdn.0voice.com/?id=3573

分享:
扫描分享到社交APP
>> rdd1 = lines.filter(lambda line: len(line.strip()) > 0) >>> rdd2 = rdd1.map(lambda x: int(x.strip())) >>> sorted_rdd = rdd2.sortBy(lambda x: x) 24/04/...&appkey=&pic=&searchPic=true")' title="分享到新浪微博" class="weibo"> >> rdd1 = lines.filter(lambda line: len(line.strip()) > 0) >>> rdd2 = rdd1.map(lambda x: int(x.strip())) >>> sorted_rdd = rdd2.sortBy(lambda x: x) 24/04/...")' title="分享到QQ好友" class="qq"> >> rdd1 = lines.filter(lambda line: len(line.strip()) > 0) >>> rdd2 = rdd1.map(lambda x: int(x.strip())) >>> sorted_rdd = rdd2.sortBy(lambda x: x) 24/04/...")' title="分享到QQ空间" class="qqzone">
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?