I am interested to prepare a class object which can inherit the attributes from another class. However, the initialization should be done by using an existing method from another class. One can try:
import pandas as pd
class Data():
def __init__(self, file):
self.df = pd.read_csv(file)
if __name__ = "__main__":
abc = Data("xyz.csv")
In this manner, the instance 'abc.df' will be a DataFrame instance which is initialized by using pandas.read_csv() method, reading the "xyz.csv" file. I wonder how one can implement the initialization such that the 'abc' itself will be the DataFrame instance instead of 'abc.df'? It shall be something like
import pandas as pd
class Data():
def __init__(self, file):
self = pd.read_csv(file) # self has all the attributes of a DataFrame instance
if __name__ = "__main__":
abc = Data("xyz.csv")
Of course, this won't work.
Edit: I found a relevant discussion on this How to subclass Pandas.DataFrame. However, I am still curious whether there is a way to create an instance by using the existing method of another instance.