我想对 pandas 数据框进行子类化,但数据框的子类也将从我自己的自定义类继承。我想这样做是因为我想创建多个子类数据框,以及其他将共享此基类的属性和方法的子类(不是数据框)。
开始我的基类是
class thing(object):
def __init__(self, item_location, name):
self.name = name
self.file = item_location
self.directory = os.path.join(*item_location.split(os.path.sep)[0:-1])
@property
def name(self):
return self._name
@name.setter
def name(self,val):
self._name = val
@property
def file(self):
return self._file
@file.setter
def file(self,val):
self._location = val
@property
def directory(self):
return self._directory
@directory.setter
def directory(self,val):
self._directory = val
现在我的子类之一将从熊猫和事物继承
class custom_dataframe(thing,pd.DataFrame):
def __init__(self, *args, **kwargs):
super(custom_dataframe,self).__init__(*args,**kwargs)
@property
def _constructor(self):
return custom_dataframe
我只是尝试制作一个空白数据框,并且只给它命名文件位置
custom_dataframe('/foobar/foobar/foobar.html','name')
我得到一个错误
(我无法将整个堆栈跟踪作为其发布在未连接到 Internet 的计算机上)
File "<stdin>", line 1, in <module>
File "<path to file with classes>", line x, in __init__
self.name = name
<a bunch of stuff going through pandas library>
File "<path to pandas generic.py>", line 4372, in __getattr__
return object.__getattribute__(self,name)
RecursionError: maximum recursion depth exceeded while calling a Python object
我正在使用熊猫 0.23.4
编辑:
改为item_location.split(os.pathsep)[0:-1]_*item_location.split(os.path.sep)[0:-1]
慕神8447489
相关分类