This may not be possible, or even a good idea but I wanted to see what options are available.
I want to create a subclass of a DataFrame that has a column as a property. E.g.
import pandas as pd
class DFWithProperties(pd.DataFrame):
"""A DataFrame that definitely has an 'a' column."""
@property
def depends_on_a(self):
return self["a"] + 1
df = DFWithProperties({"a": [1,2,3,4]})
I can obviously access this property in a similar way to other columns with
df.depends_on_a
But I also want to be able to access this column with something like
df["depends_on_a"]
or
df[["a", "depends_on_a"]]
Are there any neat tricks I can use here, or am I being too ambitious?