I am trying to build a class from pandas DataFrame. I just want to add an attribute 'name' to DataFrame class. But the codes below yield errors in recursion maximum depth reached. Which way to make it work? Thanks
import pandas as pd
class DatFrame(pd.DataFrame):
def __init__(self, name, data=None, index=None, columns=None,
dtype=None, copy=False):
self.name = name
pd.DataFrame.__init__(self, data=None, index=None,
columns=None, dtype=None, copy=False)
x = array([[9, 7, 5],
[7, 3, 1],
[8, 8, 3],
[7, 4, 3]])
cols = ['a', 'b', 'c']
index = ['D', 'E', 'F', 'G']
s = DatFrame('huy', x, index, cols)
Error: RecursionError: maximum recursion depth exceeded while calling a Python object
pd.DataFramereferenced by variabledf, then you can just dodf.name = 'huy'- juanpa.arrivillagapandasdata structures. See the docs - juanpa.arrivillaga