apache-spark - 将列表列表转换为 Spark Dataframe
问题描述
我有一个交易数据“数据”:
[ ["a","e","l"],["f","a","e","m","n"], ...]
每个子列表代表单个事务。没有标题。我正在尝试使用 pyspark 运行 FPGrowth 算法。
我尝试了以下方法:
from pyspark.ml.fpm import FPGrowth
from pyspark.context import SparkContext
from pyspark.sql.session import SparkSession
sc = SparkContext.getOrCreate();
spark = SparkSession(sc)
df = spark.createDataFrame(data,["items"])
print("1.Here")
fpGrowth = FPGrowth(itemsCol="items", minSupport=0.9, minConfidence=0.9)
model = fpGrowth.fit(df)
# Display frequent itemsets.
model.freqItemsets.show()
# Display generated association rules.
model.associationRules.show()
# transform examines the input items against all the association rules and summarize the
# consequents as prediction
model.transform(df).show()```
我得到的错误是::
IllegalArgumentException: 'requirement failed: The input column must be array, but got string.'
解决方案
DataFrame 未正确解释,请尝试使用以下格式的数据:
data = [ (["a","e","l"],),(["f","a","e","m","n"],) ]
推荐阅读
- javascript - 显示自定义叠加层的 ag-grid
- c++ - 使用终端 GCC 和 G++ 编译时,仅适用于 Box2D 的未定义参考
- python - 将值打印到 Tkinter 标签
- python - 尝试 Newton-Raphson 时获取“'float' object is not callable”
- python - 如何为 Windows 重写这个多处理代码?
- angular - 如何在过滤属性时将 ViewChildren QueryList 中的特定项目作为 ElementRef 获取?
- r - 在 R 中使用 pagedown 将 HTML 转换为 pdf
- c++ - 使用 C++ 创建一个计算器
- c# - 虽然字符串的最大大小约为 0.75GB,但 Visual Studio 显示 5GB 的使用和运行内存,为什么会有差异?
- c - 使用 Visual Studio Code 运行构建命令