[英]Unable to return a numpy array from a column of a pandas DataFrame
I have a pandas DataFrame like so: 我有一个像这样的熊猫DataFrame:
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. 我正在尝试通过将a和b作为变量在我定义的函数内传递。 For this, a should be a numpy array of the values in column A but I'm not being able to do that. 为此,a应该是A列中值的一个numpy数组,但是我无法做到这一点。
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 ValueError:FillWithScalar的输入对象不是标量
您可以使用以下方法将该列变成一个numpy数组:
a = np.array(df['Col_A'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.