【发布时间】:2016-05-24 09:45:21
【问题描述】:
我进行了研究,但没有找到任何相关信息。我想将一个简单的 pandas.DataFrame 转换为 spark 数据框,如下所示:
df = pd.DataFrame({'col1': ['a', 'b', 'c'], 'col2': [1, 2, 3]})
sc_sql.createDataFrame(df, schema=df.columns.tolist())
我得到的错误是:
TypeError: Can not infer schema for type: <class 'str'>
我尝试了一些更简单的方法:
df = pd.DataFrame([1, 2, 3])
sc_sql.createDataFrame(df)
我得到:
TypeError: Can not infer schema for type: <class 'numpy.int64'>
有什么帮助吗?是否需要手动指定架构?
sc_sql 是pyspark.sql.SQLContext,我在 python 3.4 和 spark 1.6 的 jupyter notebook 中。
谢谢!
【问题讨论】:
-
我试过代码工作正常,没有错误。
-
它不适合我,不管有没有架构......
-
您使用的是哪个 spark 版本?
-
我在 Spark 1.6.1
-
你用的是什么版本的 Pandas?
标签: python pandas apache-spark pyspark