I have a pandas dataframe with 10 columns and N rows. I want to select two columns from my data frame and put them into a NumPy 2D array with dimensions (N, 2). How to do that?
There is a way to convert a dataframe to a numpy array: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html
You could just select the columns you want:
df[['Col1','Col2']].to_numpy()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With