如何将属性添加到pandas.DataFrame的子类?
问题描述:
我想向DataFrame的子类添加属性,但出现错误:
I would like to add attributes to a subclass of DataFrame, but I get an error:
>>> 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__
语法问题.