Question Details

No question body available.

Tags

python pandas

Answers (1)

February 25, 2026 Score: 2 Rep: 5,835 Quality: Low Completeness: 50%

I was able to achieve this by creating a custom attribute inside the DataFrame and specifying the attribute name in the metadata list:

import pandas as pd

@pd.api.extensions.registerdataframeaccessor("geo") class GeoAccessor: def init(self, pandasobj): self.obj = pandasobj self.obj.metadata += ["initialshape"]

def start(self): print("Initial shape:", self.obj.shape) self.obj.initialshape = self.obj.shape return self.obj

def end(self): print("Previous shape:", self.obj.initialshape) return self.obj

df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, None]}) df.geo.start().dropna(subset=["y"]).geo.end()

returns

Initial shape: (3, 2) Previous shape: (3, 2) [The dataframe]