0

I need to make 2 arrays from a dataframe.

The first one is just an array of the column headers: np.array(df.columns) The second array would be all values from these columns (dataframe only has 1 row).

However I get this output:

array([array(66.84119159), array(67.38531331), array(67.74187959),
       array(68.00048307), array(68.22388778), array(68.39191308),
       array(68.51329445), array(68.62896006), array(68.716791),
       array(68.77379008), array(68.81400731), array(68.83634255),
       array(68.84203308), array(68.82682576), array(68.79121712),
       array(68.74733508), array(68.68588568), array(68.58466205),
       array(68.46882076), array(68.31954362), array(68.16374208),
       array(67.97388601), array(67.79819623), array(67.65393439),
       array(67.50348453), array(67.34438603), array(67.19034766),
       array(67.11430317), array(66.63700965), array(65.39818456),
       array(63.90516399)], dtype=object)

Is there a way to create an array having only one "array" and not a packaged array?

thanks

Ben
  • 183
  • 8
  • check this link https://stackoverflow.com/questions/13187778/convert-pandas-dataframe-to-numpy-array or this link https://stackoverflow.com/questions/33907776/how-to-create-an-array-of-dataframes-in-python – Daniyal Sedighpour Jun 21 '21 at 09:04

1 Answers1

0

You can use the dataframe values:

import pandas as pd
df = pd.DataFrame({'test': range(10)}).T

df.values

Out[13]: array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], dtype=int64)
Andreas
  • 8,694
  • 3
  • 14
  • 38