1

I Have pandas dataframe like this. pd df

but i want to make the 'KDB' column something like this (without the index), does anyone can help me?

[9.  3. 3.  2.  .....]

I tried to use pd.DataFrame.to_numpy() but what i got is something like this..

[[ 9]
 [ 3]
 [ 3]
 [ 2]
 ...]
haenphe
  • 37
  • 3
  • use the reshape function – Ironkey Feb 25 '20 at 15:54
  • 1
    `df.to_numpy().reshape(-1)` – Sayandip Dutta Feb 25 '20 at 15:54
  • Please do not share information as images unless absolutely necessary. See: https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors, https://idownvotedbecau.se/imageofcode, https://idownvotedbecau.se/imageofanexception/. – AMC Feb 25 '20 at 17:11
  • That looks like a NumPy array, what's the problem? – AMC Feb 25 '20 at 17:11
  • Does this answer your question? [From ND to 1D arrays](https://stackoverflow.com/questions/13730468/from-nd-to-1d-arrays) – AMC Feb 25 '20 at 17:12

3 Answers3

0

all it did was give you the column that normal, you just have to reshape it and it will make it into a row.

Now all you have to do is reshape it with df.reshape(-1) or do it all in one line with df.to_numpy().reshape(-1)

Ironkey
  • 2,568
  • 1
  • 8
  • 30
0

Just use the numpy.flatten() function to get a one-dimensional array:

>>> a = [[1], [2], [5]]
>>> a.flatten()
array([1, 2, 5])
MrLeeh
  • 5,321
  • 6
  • 33
  • 51
0

A column of a pandas DataFrame is a Series.

The underlying numpy array used by a Series is accessible via values.

What you need is just:

df['KDB'].values
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252