我想将属性添加到DataFrame的子类中,但是我收到错误:
>>> import pandas as pd
>>>class Foo(pd.DataFrame):
... def __init__(self):
... self.bar=None
...
>>> Foo()
RuntimeError: maximum recursion depth exceeded
答案 0 :(得分:2)
您想要写如下:
class Foo(pd.DataFrame):
def __init__(self):
super(Foo, self).__init__()
self.bar = None
请参阅Python's __init__
syntax问题。
答案 1 :(得分:1)
In [12]: class Foo(pd.DataFrame):
....: def __init__(self, bar=None):
....: super(Foo, self).__init__()
....: self.bar = bar
导致: -
In [30]: my_special_dataframe = Foo(bar=1)
In [31]: my_special_dataframe.bar
Out[31]: 1
In [32]: my_special_dataframe2 = Foo()
In [33]: my_special_dataframe2.bar