I have a large dataframe (10m rows, 40 columns, 7GB in memory). I would like to create a view in order to have a shorthand name for a view that is complicated to express, without adding another 2-4 GB to memory usage. In other words, I would rather type:
df2
Than:
df.loc[complicated_condition, some_columns]
The documentation states that, while using .loc
ensures that setting values modifies the original dataframe, there is still no guarantee as to whether the object returned by .loc
is a view or a copy.
I know I could assign the condition and column list to variables (e.g. df.loc[cond, cols]
), but I'm generally curious to know whether it is possible to create a view of a dataframe.
Edit: Related questions: