python - 将spark转换为pandas数据帧有异常: arrow is not supported when using file-based collect

标签 python pandas azure pyspark azure-databricks

我正在尝试将 Spark 数据帧转换为 Azure databricks 上的 pandas 数据帧。但我收到以下错误:

异常(exception):使用基于文件的收集时不支持箭头

我已使用链接尝试了引用代码:https://docs.databricks.com/spark/latest/spark-sql/spark-pandas.html

首先,我使用以下行读取 csv 文件:

#read file
df1 = spark.read.csv('/mnt/test/sample.csv', header = True)

接下来我尝试使用下面的代码将其转换为 pandas 数据框:

# Enable Arrow-based columnar data transfers
spark.conf.set("spark.sql.execution.arrow.enabled", "true")
# Convert the Spark DataFrame to a Pandas DataFrame
pandas_df = df1.select("*").toPandas()

但是在执行此操作时我收到此错误: 异常(exception):使用基于文件的收集时不支持箭头

以下是错误消息的完整扩展:

Exception: arrow is not supported when using file-based collect
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<command-3700677352136413> in <module>()
      2 spark.conf.set("spark.sql.execution.arrow.enabled", "true")
      3 # Convert the Spark DataFrame to a Pandas DataFrame
----> 4 pandas_df = df1.select("*").toPandas()

/databricks/spark/python/pyspark/sql/dataframe.py in toPandas(self)
   2169                         _check_dataframe_localize_timestamps
   2170                     import pyarrow
-> 2171                     batches = self._collectAsArrow()
   2172                     if len(batches) > 0:
   2173                         table = pyarrow.Table.from_batches(batches)

/databricks/spark/python/pyspark/sql/dataframe.py in _collectAsArrow(self)
   2225         """
   2226         if self._sc._conf.get(self._sc._jvm.PythonSecurityUtils.USE_FILE_BASED_COLLECT()):
-> 2227             raise Exception("arrow is not supported when using file-based collect")
   2228         with SCCallSiteSync(self._sc) as css:
   2229             sock_info = self._jdf.collectAsArrowToPython()

Exception: arrow is not supported when using file-based collect

有人可以帮忙吗?

最佳答案

我终于找到了解决办法。必须更改的是集群的运行时版本。创建了一个新集群并使用它的运行时版本 5.5 进行了测试,它似乎运行良好。

关于python - 将spark转换为pandas数据帧有异常: arrow is not supported when using file-based collect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57662738/

相关文章:

python - 按列对数据库行进行分组的有效方法?

Python shell 不打印回车符

python - 谷歌应用引擎 : Error in bulkloader. yaml

使用 PowerShell 软删除 Azure 存储帐户

azure - 如何删除 Azure WebApp AppSetting WEBSITE_TIME_ZONE

python - 如何根据列和数组中存在的数据填充值? Pandas

python Pandas : split a data frame based on a column value

python - 无法使用 pandas 存储多索引 csv 文件

python - 如何构建隐含概率。 python中泊松分布的矩阵

azure - 在自定义策略中使用显示控件时如何自动填充 MFA 页面上的电子邮件字段