我刚刚将http://files.grouplens.org/datasets/movielens/ml-latest-small.zip中的ratings
数据作为RDDs加载到pySpark中。我想把收视率列转换成float
。我该怎么做
我尝试在map
中使用lambda
函数,但它没有像我预期的那样工作
下面是我尝试的代码
path_data = "/ml-latest-small"
ratingsFile = sc.textFile(path_data + "/ratings.csv")
ratingsFile_2 = ratingsFile.map(lambda x: x.split(","))
header = ratingsFile_2.first()
ratingsFile_3 = ratingsFile_2.filter(lambda x: x != header)
ratingsFile_4 = ratingsFile_3.map(lambda x: float(x[2])
ratingsFile_4.take(6)
我要走了
[4.0, 4.0, 4.0, 5.0, 5.0, 3.0]
而不是
[['1', '1', 4.0, '964982703'],
['1', '3', 4.0, '964981247'],
['1', '6', 4.0, '964982224'],
['1', '47', 5.0, '964983815'],
['1', '50', 5.0, '964982931'],
['1', '70', 3.0, '964982400']]
目前没有回答
相关问题 更多 >
编程相关推荐