Please help me to understand: what is a view
in Pandas.
I know that if we change something in a view
we always make changes in the original object.
But a view of an object and the original object have different id's
for example. Does it mean that the view
is another object with reference to original object? What is the mechanism?
I tried but can't find an explanation.
import pandas as pd
import numpy as np
df = pd.DataFrame({'x': [1,2]})
print(df)
df_sub = df[0:1]
df_sub.x = -1
print(df_sub._is_view) # True
print(id(df) == id(df_sub)) # False
print(np.shares_memory(df, df_sub)) # True