In [1]:
import pandas as pd
import numpy as np

In [2]:
df_homo = pd.DataFrame({'a': [0, 1, 2], 'b': [3, 4, 5]})
print(df_homo)


   a  b
0  0  3
1  1  4
2  2  5

In [3]:
print(df_homo.dtypes)


a    int64
b    int64
dtype: object

In [4]:
df_homo_slice = df_homo.iloc[:2]
print(df_homo_slice)


   a  b
0  0  3
1  1  4

In [5]:
print(np.shares_memory(df_homo, df_homo_slice))


True

In [6]:
print(df_homo_slice._is_view)


True

In [7]:
df_homo_list = df_homo.iloc[[0, 1]]
print(df_homo_list)


   a  b
0  0  3
1  1  4

In [8]:
print(np.shares_memory(df_homo, df_homo_list))


False

In [9]:
print(df_homo_list._is_view)


False

In [10]:
print(df_homo['a'] < 2)


0     True
1     True
2    False
Name: a, dtype: bool

In [11]:
df_homo_bool = df_homo.loc[df_homo['a'] < 2]
print(df_homo_bool)


   a  b
0  0  3
1  1  4

In [12]:
print(np.shares_memory(df_homo, df_homo_bool))


False

In [13]:
print(df_homo_bool._is_view)


False

In [14]:
s_homo_scalar = df_homo.iloc[0]
print(s_homo_scalar)


a    0
b    3
Name: 0, dtype: int64

In [15]:
print(np.shares_memory(df_homo, s_homo_scalar))


True

In [16]:
print(s_homo_scalar._is_view)


True

In [17]:
s_homo_col = df_homo['a']
print(s_homo_col)


0    0
1    1
2    2
Name: a, dtype: int64

In [18]:
print(np.shares_memory(df_homo, s_homo_col))


True

In [19]:
print(s_homo_col._is_view)


True

In [20]:
df_homo_col_multi = df_homo[['a', 'b']]
print(df_homo_col_multi)


   a  b
0  0  3
1  1  4
2  2  5

In [21]:
print(np.shares_memory(df_homo, df_homo_col_multi))


False

In [22]:
print(df_homo_col_multi._is_view)


False

In [23]:
df_homo.iat[0, 0] = 100
print(df_homo)


     a  b
0  100  3
1    1  4
2    2  5

In [24]:
print(df_homo_slice)


     a  b
0  100  3
1    1  4

In [25]:
print(df_homo_list)


   a  b
0  0  3
1  1  4

In [26]:
print(df_homo_bool)


   a  b
0  0  3
1  1  4

In [27]:
print(s_homo_scalar)


a    100
b      3
Name: 0, dtype: int64

In [28]:
print(s_homo_col)


0    100
1      1
2      2
Name: a, dtype: int64

In [29]:
print(df_homo_col_multi)


   a  b
0  0  3
1  1  4
2  2  5

In [30]:
df_hetero = pd.DataFrame({'a': [0, 1, 2], 'b': ['x', 'y', 'z']})
print(df_hetero)


   a  b
0  0  x
1  1  y
2  2  z

In [31]:
print(df_hetero.dtypes)


a     int64
b    object
dtype: object

In [32]:
df_hetero_slice = df_hetero.iloc[:2]
print(df_hetero_slice)


   a  b
0  0  x
1  1  y

In [33]:
print(np.shares_memory(df_hetero, df_hetero_slice))


False

In [34]:
print(df_hetero_slice._is_view)


False

In [35]:
df_hetero_slice2 = df_hetero.iloc[:2, 0:]
print(df_hetero_slice2)


   a  b
0  0  x
1  1  y

In [36]:
print(np.shares_memory(df_hetero, df_hetero_slice2))


False

In [37]:
print(df_hetero_slice2._is_view)


False

In [38]:
df_hetero_list = df_hetero.iloc[[0, 1]]
print(df_hetero_list)


   a  b
0  0  x
1  1  y

In [39]:
print(np.shares_memory(df_hetero, df_hetero_list))


False

In [40]:
print(df_hetero_list._is_view)


False

In [41]:
df_hetero_bool = df_hetero.loc[df_hetero['a'] < 2]
print(df_hetero_bool)


   a  b
0  0  x
1  1  y

In [42]:
print(df_hetero_bool._is_view)


False

In [43]:
print(df_hetero_bool._is_view)


False

In [44]:
s_hetero_scalar = df_hetero.iloc[0]
print(s_hetero_scalar)


a    0
b    x
Name: 0, dtype: object

In [45]:
print(np.shares_memory(df_hetero, s_hetero_scalar))


False

In [46]:
print(s_hetero_scalar._is_view)


False

In [47]:
s_hetero_col = df_hetero['a']
print(s_hetero_col)


0    0
1    1
2    2
Name: a, dtype: int64

In [48]:
print(np.shares_memory(df_hetero, s_hetero_col))


False

In [49]:
print(s_hetero_col._is_view)


True

In [50]:
df_hetero_col_multi = df_hetero[['a', 'b']]
print(df_hetero_col_multi)


   a  b
0  0  x
1  1  y
2  2  z

In [51]:
print(np.shares_memory(df_hetero, df_hetero_col_multi))


False

In [52]:
print(df_hetero_col_multi._is_view)


False

In [53]:
df_hetero.iat[0, 0] = 100
print(df_hetero)


     a  b
0  100  x
1    1  y
2    2  z

In [54]:
print(df_hetero_slice)


     a  b
0  100  x
1    1  y

In [55]:
print(df_hetero_slice2)


   a  b
0  0  x
1  1  y

In [56]:
print(df_hetero_list)


   a  b
0  0  x
1  1  y

In [57]:
print(df_hetero_bool)


   a  b
0  0  x
1  1  y

In [58]:
print(s_hetero_scalar)


a    0
b    x
Name: 0, dtype: object

In [59]:
print(s_hetero_col)


0    100
1      1
2      2
Name: a, dtype: int64

In [60]:
print(df_hetero_col_multi)


   a  b
0  0  x
1  1  y
2  2  z