我在 MS Azure 上使用 databricks,每次将 pandas 数据帧转换为 Pyspark 数据帧时都会收到此警告:
/databricks/spark/python/pyspark/sql/pandas/conversion.py:539: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
arrow_data = [[(c, t) for (_, c), t in zip(pdf_slice.iteritems(), arrow_types)]
我使用的代码是:
df_spk = spark.createDataFrame(df_pd)
由于我找不到上面一行的替代方法,因此我无法使用较新版本的 Python。 有人有什么想法吗?
预先感谢您,
最佳答案
我认为您看到的警告消息与 Python 中的 FutureWarning 有关,
表示 iteritems() 方法已弃用,并将在未来版本中删除。
此警告消息来自 pandas 到 PySpark DataFrame 的转换过程。
要忽略或不显示此类 FutureWarning 消息,
您可以在脚本的开头使用以下代码片段
import warnings
warnings.filterwarnings("ignore", category=FutureWarning)
上面的代码片段将忽略代码中的所有 FutureWarning 消息。
如果您只想忽略与 ititems() 方法相关的 FutureWarning 消息,
您可以使用下面的代码片段
import warnings
warnings.filterwarnings("ignore", message="iteritems is deprecated")
另外,请考虑尝试升级到使用 .items() 方法而不是 iteritems() 的 PySpark 或 pandas 的新版本。
关于azure - Pandas 到 Pyspark 警告消息 : "iteritems is deprecated and will be removed in a future version",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75973024/