如何泡菜自定义python对象包含火花数据框作为属性
我创建了一个自定义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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论