相关疑难解决方法(0)

Pyspark将标准列表转换为数据框

这种情况非常简单,我需要使用以下代码将python列表转换为数据框

from pyspark.sql.types import StructType
from pyspark.sql.types import StructField
from pyspark.sql.types import StringType, IntegerType

schema = StructType([StructField("value", IntegerType(), True)])
my_list = [1, 2, 3, 4]
rdd = sc.parallelize(my_list)
df = sqlContext.createDataFrame(rdd, schema)

df.show()
Run Code Online (Sandbox Code Playgroud)

它失败并出现以下错误:

    raise TypeError("StructType can not accept object %r in type %s" % (obj, type(obj)))
TypeError: StructType can not accept object 1 in type <class 'int'>
Run Code Online (Sandbox Code Playgroud)

python apache-spark pyspark pyspark-sql

18
推荐指数
2
解决办法
3万
查看次数

标签 统计

apache-spark ×1

pyspark ×1

pyspark-sql ×1

python ×1