You can subclass pandas.DataFrame
as explained here. It is a little tricky but possible...
You can add an attribute directly to the instance of DataFrame. Not recommended but possible.
You can also create a class containing a DataFrame and overload the __repr__
and to_csv
methods as mentioned below
Here is an example of the 2nd solution
import pandas as pd
df = pd.DataFrame({'col1':a, 'col2':b})
df.myname ='my_super_name'
Here is an example of the 3rd solution
import pandas as pd
class MyDataFrame():
def __init__(self, _myname, *args, **kwargs):
self.myname = _myname
self.df = pd.DataFrame(*args, **kwargs)
def __repr__(self):
return self.myname
def to_csv(self):
self.df.to_csv(self.myname + '.csv')
a = [0, 1, 2, 3]
b = [2, 3, 4, 5]
df = MyDataFrame('my_data_frame', {'col1':a, 'col2':b})
print(df)
df.to_csv()