Невозможно создать Dataframe в PySpark - PullRequest
0 голосов
/ 01 октября 2018

Я хочу создать Dataframe в PySpark со следующим кодом

from pyspark.sql import *
from pyspark.sql.types import *

temp = Row("DESC", "ID")
temp1 = temp('Description1323', 123)

print temp1

schema = StructType([StructField("DESC", StringType(), False),
                     StructField("ID", IntegerType(), False)])

df = spark.createDataFrame(temp1, schema)

Но я получаю следующую ошибку:

TypeError: StructType не может принять объект 'Description1323'in type type' str '

Что не так с моим кодом?

1 Ответ

0 голосов
/ 01 октября 2018

Проблема в том, что вы передаете Row, где вы должны передавать список Row с.Попробуйте это:

from pyspark.sql import *
from pyspark.sql.types import *

temp = Row("DESC", "ID")
temp1 = temp('Description1323', 123)

print temp1

schema = StructType([StructField("DESC", StringType(), False),
                     StructField("ID", IntegerType(), False)])

df = spark.createDataFrame([temp1], schema)

df.show()

И результат:

+---------------+---+
|           DESC| ID|
+---------------+---+
|Description1323|123|
+---------------+---+
...