Skip to content
Advertisement

How to create the Numpy array X of shape (2638, 1838) for a dataframe has shape (2638, 1840)?

enter image description here

enter image description here

Hi, can someone please help me with this? What should do if I want to use NumPy to get an array X which has a shape (2638, 1838) while the dataframe has a shape of (2638, 1840)?

Here is my code:

JavaScript

Advertisement

Answer

Conversion to Numpy and back to Pandas, as advised in one of comments to your post, is not any elegant solution. Fortunately, Pandas is able to do your tasks on its own.

Your first task is to select all columns of the input df except for 2 last columns (cell_type and cell_type_string). To do it, run:

JavaScript

The second task is to extract the last but one column (second from the end). To do it, run:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement