In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame(data=[[1, 2, 3], [4, 5, 6]], columns=['a', 'b', 'c'])
print(df)
In [3]:
a = df.to_numpy()
print(a)
In [4]:
print(type(a))
In [5]:
print(np.shares_memory(df, a))
In [6]:
a[0, 0] = 100
print(a)
In [7]:
print(df)
In [8]:
a_copy = df.to_numpy(copy=True)
print(a_copy)
In [9]:
print(np.shares_memory(df, a_copy))
In [10]:
a_copy[0, 0] = 10
print(a_copy)
In [11]:
print(df)
In [12]:
a_cols = df[['a', 'c']].to_numpy()
print(a_cols)
In [13]:
print(np.shares_memory(df, a_cols))
In [14]:
a_f = df.to_numpy(dtype=float)
print(a_f)
In [15]:
print(np.shares_memory(df, a_f))