In pandas it is always important to know if something is a view on a DataFrame. I just wanted to know if there is some special attribute or way to distinguish a view from a genuine DataFrame. I tried the following without success (see below)
#Create toy data and a view
df = pd.DataFrame({"foo": [1, 2, 3], "bar": [4, 5, 6]})
view = df[:]
#Check if there are any attributes unique to proper dfs vs views and vice versa
view_vars = set((x for x in dir(view) if not x.startswith("_")))
df_vars = set((x for x in dir(df) if not x.startswith("_")))
view_vars ^ df_vars # no differences
#Repeat check for all attributes (i.e. including attributes with underscore in front)
view_vars = set((x for x in dir(view) ))
df_vars = set((x for x in dir(df) ))
view_vars ^ df_vars # still no differences
#Check numpy base values -> same
df.values.base
view.values.base
Can anyone provide me with some advice on how to programmatically disentangle a view from a genuine (copy of a) DataFrame?