如何泡菜自定义python对象包含火花数据框作为属性

发布于 2025-02-10 19:20:34 字数 611 浏览 2 评论 0原文

我创建了一个自定义Python类,该类拥有三个类型(PY)Spark DataFrame的属性。上述班级的构造函数看起来像这样:

class MyClass:
    def __init__(self, df_a, df_b, df_c):
        self.a = df_a
        self.b = df_b
        self.c = df_c

我想保存本类已经实例化的对象,并能够在将来加载它。但是,如果我尝试使用泡菜保存它,则它会抛出typeerror:cockle _thread.lock对象 exception。据我所知,由于无法直接腌制Spark DataFrames,因此会出现此例外。

我已经研究了功能df.rdd.saveaspicklefile(filename),因为我可以使用它独立于三个数据范围来腌制,但这不是我想要的。我想拥有一个单个泡菜对象。

注意:每当我说Pickle时,我都可以使用任何其他序列化类型,只要它允许我保存和加载一个对象。

I've created a custom Python class which holds three attributes of type (Py)Spark DataFrame. The constructor of said class looks like this:

class MyClass:
    def __init__(self, df_a, df_b, df_c):
        self.a = df_a
        self.b = df_b
        self.c = df_c

I would like to save an already instantiated object of this class and be able to load it in the future. However, if I try to save it using pickle it throws a TypeError: can't pickle _thread.lock objects exception. As far as I understood, this exception arises because spark dataframes cannot be pickled directly.

I've looked into the function df.rdd.saveAsPickleFile(filename), since I could use it to pickle independently the three dataframes, but that's not really what I want. I want to have a single pickle object.

Note: whenever I'm saying pickle, I could probably work with any other serialization type, as long as it allows me to save and load a single object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文