Nocas
Nocas

Reputation: 397

Unable to return a numpy array from a column of a pandas DataFrame

I have a pandas DataFrame like so:

      Col_A     Col_B
   0.   1         5
   1.   2         6
   2.   3         7
   3.   4         8

I'm trying to do this to pass a and b as variables inside a function I'm defining. For this, a should be a numpy array of the values in column A but I'm not being able to do that.

So far I've tried:

a = np.empty(1); a.fill(df[0])

But it returns:

ValueError: Input object to FillWithScalar is not a scalar

Upvotes: 0

Views: 800

Answers (1)

kierabeth
kierabeth

Reputation: 98

You could take the column and turn it into a numpy array using the following:

a = np.array(df['Col_A'])

Upvotes: 1

Related Questions