python - 将 DataFrame 转换为字典列表时如何避免此火花问题?
问题描述
我想将我的 spark DataFrame 转换为字典列表。
new_df = list(map(lambda row: row.asDict(), df_base.collect()))
但是当我运行上述内容时,我不断收到以下错误。
org.apache.spark.SparkException: Job aborted due to stage failure: Total size of serialized results of 5 tasks (4.3 GiB) is bigger than spark.driver.maxResultSize 4.0 GiB.
我该如何解决这个问题?有可能做我想做的事吗?
解决方案
简短的回答是使用df_base.toLocalIterator()
而不是收集()。但是你真的需要将超过 4GB 的数据加载到本地 python 列表中吗?您是否考虑使用 df_base.toPandas() 或使用 spark 来运行所有代码。
new_df = list(map(lambda row: row.asDict(), df_base.toLocalIterator()))
推荐阅读
- android - 如何解决recyclerv视图列表更新延迟
- c# - 如何使用 DirectoryEntry 更新 Active Directory 中的数据?
- laravel - Laravel Eloquent 获取可能存在或不存在的嵌套急切加载的属性
- reactjs - npm start 在浏览器中显示生成的 js 文件
- visual-studio - Which key is the up arrow shortcut in Visual Studio code for OSX?
- php - 总是 MySQL 什么也不输出。告诉我为什么?
- javascript - 如果所有子类别复选框均已选中,则应自动选中父复选框
- javascript - 使用 Javascript 将两个变量连接成一个新变量
- java - 在“for 语句”中打印出数组
- react-native - 如何水平显示具有 2 列的 Scrollview 图像