I like to store metadata about a dataframe by simply setting an attribute and its corresponding value, like this:
df.foo = "bar"
However, I've found that attributes stored like this are gone once I slice the dataframe:
df.foo = "bar"
df[:100].foo
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\admin\PycharmProjects\project\venv\lib\site-packages\pandas\core\generic.py", line 5465, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'foo'
I wonder if this behavior can be changed, similar to how drop=True
or inplace=True
change the way attributes like df.set_index(args)
work. I didn't find anything helpful in the pandas docs.