How to create an array from two columns in pandas
You can also achieve the same output with the below code.
import numpy as np
np.array(df[['col1','col2']])
Out[60]:
array([[0, 1],
[2, 3],
[4, 5]])
You can access the underlying numpy array via the to_numpy
method:
df[['col1', 'col2']].to_numpy()
Out:
array([[0, 1],
[2, 3],
[4, 5]])
.values
attribute will do the same if you are on an earlier version (before v0.24).