无法推断类型的架构:<type'str'>

oct*_*ian 5 python apache-spark pyspark

我有以下使用Spark的Python代码:

from pyspark.sql import Row

def simulate(a, b, c):
  dict = Row(a=a, b=b, c=c)
  df = sqlContext.createDataFrame(dict)
  return df

df = simulate("a","b",10)
df.collect()
Run Code Online (Sandbox Code Playgroud)

我正在创建一个Row对象,我想将其保存为DataFrame.

但是,我收到此错误:

TypeError: Can not infer schema for type: <type 'str'>
Run Code Online (Sandbox Code Playgroud)

它出现在这一行:

df = sqlContext.createDataFrame(dict)
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

小智 7

创建单个元素数据框是没有意义的.如果你想使它尽管使用列表仍然有效:df = sqlContext.createDataFrame([dict])