我想将属性添加到 DataFrame 的子类,但出现错误:
>>> import pandas as pd
>>>class Foo(pd.DataFrame):
... def __init__(self):
... self.bar=None
...
>>> Foo()
RuntimeError: maximum recursion depth exceeded
我想将属性添加到 DataFrame 的子类,但出现错误:
>>> import pandas as pd
>>>class Foo(pd.DataFrame):
... def __init__(self):
... self.bar=None
...
>>> Foo()
RuntimeError: maximum recursion depth exceeded
你想这样写:
class Foo(pd.DataFrame):
def __init__(self):
super(Foo, self).__init__()
self.bar = None
请参阅Python 的__init__
语法问题。
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