我在pyspark 1.4中本地处理数据帧,在使用drop-duplicates方法时遇到问题。一直返回错误“attribute error:”list“object没有属性”dropDuplicates“。不太清楚为什么我似乎在遵循latest documentation中的语法。好像我缺少那个功能的导入。
#loading the CSV file into an RDD in order to start working with the data
rdd1 = sc.textFile("C:\myfilename.csv").map(lambda line: (line.split(",")[0], line.split(",")[1], line.split(",")[2], line.split(",")[3])).collect()
#loading the RDD object into a dataframe and assigning column names
df1 = sqlContext.createDataFrame(rdd1, ['column1', 'column2', 'column3', 'column4']).collect()
#dropping duplicates from the dataframe
df1.dropDuplicates().show()
这不是一个重要的问题。只需在错误的对象上调用
.dropDuplicates()
。虽然sqlContext.createDataFrame(rdd1, ...)
的类是pyspark.sql.dataframe.DataFrame
,但是在应用.collect()
之后,它是一个普通的Pythonlist
,并且列表不提供dropDuplicates
方法。你想要的是这样的东西:如果您有一个数据帧,并且希望删除所有重复项--引用特定列中的重复项(称为“colName”):
重复数据消除前的计数:
执行重复数据消除(将要进行重复数据消除的列转换为字符串类型):
可以使用已排序的groupby检查是否已删除重复项:
相关问题 更多 >
编程相关推荐