Python 3.x Python在整体类设计中很好地集成了Pandas数据框架
我有一个关于课堂设计的简短问题。我的程序使用Python 3.x Python在整体类设计中很好地集成了Pandas数据框架,python-3.x,oop,pandas,Python 3.x,Oop,Pandas,我有一个关于课堂设计的简短问题。我的程序使用数据类加载各种数据帧作为类属性。还有一些getter方法。此外,我还有一个类,它使用数据提供的数据(约150 MB)作为类属性。Foobar\u集合类只需要一个实例,因为它的任务是跟踪所有Foo实例。从概念上看,它是这样的: class Data(object): def __init__(self): self.x = [1,2,3,4] #actually load a pandas dataframe here def g
数据
类加载各种数据帧
作为类属性。还有一些getter方法。此外,我还有一个类,它使用数据提供的数据(约150 MB)作为类属性。Foobar\u集合
类只需要一个实例,因为它的任务是跟踪所有Foo
实例。从概念上看,它是这样的:
class Data(object):
def __init__(self):
self.x = [1,2,3,4] #actually load a pandas dataframe here
def getX(self,i):
return self.x[i]
class Foobar_Collection(dict):
data = Data() #### Is this okay?
def __init__(self, *arg, **kw):
super(Foobar_Collection, self).__init__(*arg,**kw)
def foobar(self,*arg,**kw):
foo = Foo(*arg,**kw)
self[foo.name] = foo
return foo
def run_myMethodForAllfoobars(self):
for name in self:
self[name].myMethod(10)
return None
class Foo(object):
def __init__(self,name):
self.name = name
self.num = None
def myMethod(self,i):
self.num = Foobar_Collection.data.getX(i) #### Is this okay?
return None
#just to illustrate the purpose of Foobar_Collection
Foobar = Foobar_Collection()
Foobar.foobar('A')
Foobar.foobar('B')
很好用。我只是想知道这是否是一种“整合”数据的好方法?我希望能对这个设计提出一些意见