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

1

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the reply. I still get this packaged version with 1 number = 1 array
@Ben yes but you could do something like this: df.values[0] is there a reason not to?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.